9 Runs a command and returns its output as a string. The exit status of the
12 string run_command(const StringList &argv)
22 char *argv_[argv.size()+1];
25 for(StringList::const_iterator i=argv.begin(); i!=argv.end(); ++i)
26 argv_[j++]=strdup(i->c_str());
33 execvp(argv_[0], argv_);
37 cerr<<"Failed to execute "<<argv.front()<<'\n';
44 int len=read(pfd[0], buf, sizeof(buf));
47 if(waitpid(pid, 0, WNOHANG))
51 result.append(buf, len);