PAR2Set/utils: add the ability to redirect stdout
authorIra W. Snyder <devel@irasnyder.com>
Wed, 7 May 2014 01:07:15 +0000 (18:07 -0700)
committerIra W. Snyder <devel@irasnyder.com>
Wed, 7 May 2014 01:07:15 +0000 (18:07 -0700)
The subprocess module supports redirecting stdout to an open file
descriptor. Expose this in our wrapper.

PAR2Set/utils.py

index 8cd9408..242f4c5 100644 (file)
@@ -93,11 +93,12 @@ def hasAMatch(regex, iterateable, ignoreCase=True):
 # Run the specified command-list in the given directory
 # @cmd a list formatted for the subprocess module
 # @directory the directory in which to run the command
 # Run the specified command-list in the given directory
 # @cmd a list formatted for the subprocess module
 # @directory the directory in which to run the command
+# @stdout the stdout file descriptor, following the rules of the subprocess module
 # @return the status code returned by the command
 #
 # Exceptions:
 # subprocess.CalledProcessError when the called process return code is not 0
 # @return the status code returned by the command
 #
 # Exceptions:
 # subprocess.CalledProcessError when the called process return code is not 0
-def runCommand(cmd, directory):
+def runCommand(cmd, directory, stdout=None):
 
     logging.debug('===== BEGIN runCommand() DEBUG =====')
     logging.debug('Directory: %s' % directory)
 
     logging.debug('===== BEGIN runCommand() DEBUG =====')
     logging.debug('Directory: %s' % directory)
@@ -106,7 +107,7 @@ def runCommand(cmd, directory):
         logging.debug('-> %s' % arg)
     logging.debug('===== END runCommand() DEBUG =====')
 
         logging.debug('-> %s' % arg)
     logging.debug('===== END runCommand() DEBUG =====')
 
-    return subprocess.check_call(cmd, cwd=directory)
+    return subprocess.check_call(cmd, cwd=directory, stdout=stdout)
 
 ################################################################################
 
 
 ################################################################################