aboutsummaryrefslogtreecommitdiff
path: root/src/functionexecute.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-12-21 18:04:02 +0000
committerMike Buland <eichlan@xagasoft.com>2009-12-21 18:04:02 +0000
commitfb28f6800864176be2ffca29e8e664b641f33170 (patch)
treeba9180ac442939edc4eacbe1fdae93c5a7f87cee /src/functionexecute.cpp
parent51e21a316be6e052251b3dfc7d671061ebd67cee (diff)
downloadbuild-fb28f6800864176be2ffca29e8e664b641f33170.tar.gz
build-fb28f6800864176be2ffca29e8e664b641f33170.tar.bz2
build-fb28f6800864176be2ffca29e8e664b641f33170.tar.xz
build-fb28f6800864176be2ffca29e8e664b641f33170.zip
m3 is copied into trunk, we should be good to go, now.
Diffstat (limited to 'src/functionexecute.cpp')
-rw-r--r--src/functionexecute.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/functionexecute.cpp b/src/functionexecute.cpp
new file mode 100644
index 0000000..619d2c2
--- /dev/null
+++ b/src/functionexecute.cpp
@@ -0,0 +1,68 @@
1#include "functionexecute.h"
2#include "context.h"
3#include "view.h"
4
5#include <bu/sio.h>
6#include <bu/process.h>
7using namespace Bu;
8
9FunctionExecute::FunctionExecute()
10{
11}
12
13FunctionExecute::~FunctionExecute()
14{
15}
16
17Bu::FString FunctionExecute::getName() const
18{
19 return "execute";
20}
21
22Variable FunctionExecute::call( Variable &/*input*/, VarList lParams )
23{
24 // TODO This is lame, really lame, we need to exec on our own and process
25 // output appropriately.
26 pContext->getView()->cmdStarted( lParams.first().getString() );
27 Process pCmd( Process::Both, "/bin/bash", "/bin/bash", "-c",
28 lParams.first().getString().getStr(), NULL );
29 FString sStdOut, sStdErr;
30 while( pCmd.isRunning() )
31 {
32 char buf[4096];
33 bool out, err;
34 pCmd.select( out, err );
35 if( err )
36 {
37 int iRead = pCmd.readErr( buf, 4096 );
38 sStdErr.append( buf, iRead );
39 //sio << "Read " << iRead << " bytes of stderr." << sio.nl;
40 }
41 if( out )
42 {
43 int iRead = pCmd.read( buf, 4096 );
44 sStdOut.append( buf, iRead );
45 //sio << "Read " << iRead << " bytes of stdout." << sio.nl;
46 }
47 }
48
49 pContext->getView()->cmdFinished(
50 sStdOut, sStdErr, pCmd.childExitStatus()
51 );
52 if( pCmd.childExited() )
53 {
54 if( pCmd.childExitStatus() != 0 )
55 {
56 throw Bu::ExceptionBase("Command exited with errorcode %d.", pCmd.childExitStatus() );
57 }
58 }
59 else
60 {
61 pContext->getView()->cmdFinished(
62 sStdOut, sStdErr, pCmd.childExitStatus()
63 );
64 throw Bu::ExceptionBase("Command Failed");
65 }
66 return Variable( pCmd.childExitStatus() );
67}
68