X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fmisc.cpp;h=30239a48eaed27a4bef5cf8ad8ca4ee80e154e3f;hb=7aeaa4ba965f596edad438c02e345a8843f7469a;hp=37616a95f3dfeba4a5994d6f00eb727f04caaccf;hpb=4dc31cca056ea293d320928f61fef0558089d32d;p=builder.git diff --git a/source/misc.cpp b/source/misc.cpp index 37616a9..30239a4 100644 --- a/source/misc.cpp +++ b/source/misc.cpp @@ -1,12 +1,22 @@ +/* $Id$ + +This file is part of builder +Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + #include #include -#include #include "misc.h" using namespace std; using namespace Msp; -string run_command(const list &argv) +/** +Runs a command and returns its output as a string. The exit status of the +command is lost. +*/ +string run_command(const StringList &argv) { int pfd[2]; pipe(pfd); @@ -17,12 +27,16 @@ string run_command(const list &argv) if(pid==0) { char *argv_[argv.size()+1]; - for(CountingIterator::const_iterator> i=argv.begin(); i!=argv.end(); ++i) - argv_[i.count()]=strdup(i->c_str()); - argv_[argv.size()]=0; + + unsigned j=0; + for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i) + argv_[j++]=strdup(i->c_str()); + argv_[j]=0; + close(pfd[0]); dup2(pfd[1], 1); dup2(pfd[1], 2); + execvp(argv_[0], argv_); ::exit(1); } @@ -44,7 +58,7 @@ string run_command(const list &argv) result.append(buf, len); } } - + return result; }