]> git.tdb.fi Git - builder.git/blobdiff - source/misc.cpp
Reorder class members
[builder.git] / source / misc.cpp
index 35953a74efb00b4a1ad1e1979469eecd74427c72..4d2019a5fd28c2a1954884f8683fdb4a691b5292 100644 (file)
@@ -1,15 +1,20 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2009  Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <iostream>
 #include <sys/wait.h>
-#include <msp/iter.h>
+#include <fcntl.h>
+#include <cstdlib>
+#include <cstring>
 #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)
 {
        int pfd[2];
@@ -21,12 +26,19 @@ string run_command(const StringList &argv)
        if(pid==0)
        {
                char *argv_[argv.size()+1];
-               for(CountingIterator<const string, StringList::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);
+               close(pfd[1]);
+               int devnull=open("/dev/null", O_WRONLY);
+               dup2(devnull, 2);
+               close(devnull);
+
                execvp(argv_[0], argv_);
                ::exit(1);
        }
@@ -48,7 +60,7 @@ string run_command(const StringList &argv)
                                result.append(buf, len);
                }
        }
-       
+
        return result;
 }