]> git.tdb.fi Git - builder.git/blobdiff - source/misc.cpp
Bugfixes
[builder.git] / source / misc.cpp
index 0d7a13de81931dcfb2e5b7e82229d32c9711d5a7..cf180ce1beada0ab0a4ce2dc23e829fdd3d258a9 100644 (file)
@@ -1,14 +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 <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];
@@ -28,7 +34,10 @@ string run_command(const StringList &argv)
 
                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);
@@ -50,6 +59,7 @@ string run_command(const StringList &argv)
                        else
                                result.append(buf, len);
                }
+               close(pfd[0]);
        }
 
        return result;