Issue 2228: discard stderr by using os.devnull
authorGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 9 Nov 2008 02:02:04 +0000 (02:02 +0000)
committerGregNoel <GregNoel@fdb21ef1-2011-0410-befe-b5e4ea1792b1>
Sun, 9 Nov 2008 02:02:04 +0000 (02:02 +0000)
git-svn-id: http://scons.tigris.org/svn/scons/trunk@3774 fdb21ef1-2011-0410-befe-b5e4ea1792b1

src/engine/SCons/Action.py
src/engine/SCons/Environment.py
src/engine/SCons/Tool/g++.py
src/engine/SCons/Tool/gcc.py

index 70fafe00f9378ffa7fb2143a83bb938da579b418..6ce51168a9edce1e87d10d9f5a925749f9148358 100644 (file)
@@ -102,7 +102,6 @@ __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__"
 import cPickle
 import dis
 import os
-import os.path
 import string
 import sys
 import subprocess
@@ -579,8 +578,17 @@ def get_default_ENV(env):
 # it'll have to be tweaked to get the full desired functionality.
 # one special arg (so far?), 'error', to tell what to do with exceptions.
 def _subproc(env, cmd, error = 'ignore', **kw):
-    """Do setup for a subprocess.Popen() call"""
-    ### TODO: allow std{in,out,err} to be "'devnull'" (see issue 2228)
+    """Do common setup for a subprocess.Popen() call"""
+    # allow std{in,out,err} to be "'devnull'"
+    io = kw.get('stdin')
+    if is_String(io) and io == 'devnull':
+        kw['stdin'] = open(os.devnull)
+    io = kw.get('stdout')
+    if is_String(io) and io == 'devnull':
+        kw['stdout'] = open(os.devnull, 'w')
+    io = kw.get('stderr')
+    if is_String(io) and io == 'devnull':
+        kw['stderr'] = open(os.devnull, 'w')
 
     # Figure out what shell environment to use
     ENV = kw.get('env', None)
@@ -971,7 +979,7 @@ class FunctionAction(_ActionAction):
                 # probably be best to always return them by value here, but
                 # some codes do not check the return value of Actions and I do
                 # not have the time to modify them at this point.
-                if (exc_info[1] and 
+                if (exc_info[1] and
                     not isinstance(exc_info[1],EnvironmentError)):
                     raise result
 
index 5ac10ac124c303fe46f32ca23bb5bff44698ea55..327e0d108cb60832be22e26c90b898c5c772e13a 100644 (file)
@@ -527,7 +527,8 @@ class SubstitutionEnvironment:
     def backtick(self, command):
         import subprocess
         # common arguments
-        kw = { 'stdout' : subprocess.PIPE,
+        kw = { 'stdin' : 'devnull',
+               'stdout' : subprocess.PIPE,
                'stderr' : subprocess.PIPE,
                'universal_newlines' : True,
              }
index 61d095e575da086a4405a76e89d812347a0d3da9..b492604b5aaaf5e69edd48830d7ce5da4792f139 100644 (file)
@@ -65,7 +65,8 @@ def generate(env):
     if env['CXX']:
         #pipe = SCons.Action._subproc(env, [env['CXX'], '-dumpversion'],
         pipe = SCons.Action._subproc(env, [env['CXX'], '--version'],
-                                     stderr = subprocess.PIPE,
+                                     stdin = 'devnull',
+                                     stderr = 'devnull',
                                      stdout = subprocess.PIPE)
         if pipe.wait() != 0: return
         # -dumpversion was added in GCC 3.0.  As long as we're supporting
index 7d2b1b87b3511d21ca364e0d1d9bad4d1326ae45..d074191716f56506f0502324ed5b61efa4344ea5 100644 (file)
@@ -55,7 +55,8 @@ def generate(env):
     if env['CC']:
         #pipe = SCons.Action._subproc(env, [env['CC'], '-dumpversion'],
         pipe = SCons.Action._subproc(env, [env['CC'], '--version'],
-                                     stderr = subprocess.PIPE,
+                                     stdin = 'devnull',
+                                     stderr = 'devnull',
                                      stdout = subprocess.PIPE)
         if pipe.wait() != 0: return
         # -dumpversion was added in GCC 3.0.  As long as we're supporting