X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmisc.cpp;h=f540121442f6777aa4026e73cb803bd576f9f6f4;hb=43bd25ffcb0b4f7882773f4676b209a99cb73c04;hp=ab61d9f1fe0f38058917de552b6d8bfc3b0deb19;hpb=3772879ebdf452eeb9e8e2c04c07338c4933a3ed;p=builder.git diff --git a/source/misc.cpp b/source/misc.cpp index ab61d9f..f540121 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -1,45 +1,34 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include #include #include #include #include +#include #include "misc.h" using namespace std; using namespace Msp; -/** -Runs a command and returns its output as a string. The exit status of the -command is lost. -*/ -string run_command(const StringList &argv) +string run_command(const StringList &argv, int *status) { int pfd[2]; pipe(pfd); string result; - pid_t pid=fork(); + pid_t pid = fork(); if(pid==0) { char *argv_[argv.size()+1]; - unsigned j=0; + unsigned j = 0; for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i) - argv_[j++]=strdup(i->c_str()); - argv_[j]=0; + argv_[j++] = strdup(i->c_str()); + argv_[j] = 0; close(pfd[0]); dup2(pfd[1], 1); close(pfd[1]); - int devnull=open("/dev/null", O_WRONLY); + int devnull = open("/dev/null", O_WRONLY); dup2(devnull, 2); close(devnull); @@ -47,22 +36,33 @@ string run_command(const StringList &argv) ::exit(1); } else if(pid==-1) - cerr<<"Failed to execute "<