+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
#include <iostream>
#include <sys/wait.h>
-#include <msp/iter.h>
#include "misc.h"
using namespace std;
using namespace Msp;
-string run_command(const list<string> &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);
if(pid==0)
{
char *argv_[argv.size()+1];
- for(CountingIterator<const string, list<string>::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);
}
result.append(buf, len);
}
}
-
+
return result;
}