diff options
author | Kenneth Graunke <kenneth@whitecape.org> | 2012-04-20 00:16:59 -0700 |
---|---|---|
committer | Kenneth Graunke <kenneth@whitecape.org> | 2012-04-20 00:16:59 -0700 |
commit | b512f1417631a8f548e9971f74d1d3820a987ea7 (patch) | |
tree | d940d338e7403b840cfe54dd2bf3443344443a16 | |
parent | f8f8d571ce7ea590ead5e90d6137d8bac60e40f5 (diff) |
PROCESS: env.
-rw-r--r-- | framework/process.py | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/framework/process.py b/framework/process.py index d15528e..b1100a6 100644 --- a/framework/process.py +++ b/framework/process.py @@ -27,15 +27,27 @@ import subprocess __all__ = ['runProgram'] -def runProgram(cmd, timeout): +def runProgram(cmd, timeout, env = None): """Run a program with a timeout in case it never terminates. cmd -- List of command and arguments. See subprocess.Popen. timeout -- Fractional number of seconds to wait before killing the program. + env -- A dictionary containing additional environment variables to set. Returns a 4-tuple: (stdout, stderr, return code, <finished before timeout>) """ - proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) + + if env: + fullEnv = os.environ.copy() + fullEnv.update(env) + else: + fullEnv = os.environ + + proc = subprocess.Popen(cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=fullEnv, + universal_newlines=True) timeoutExpired = [] # A bool would make sense, but it needs to be mutable. def timerCallback(): timeoutExpired.append(True) |