--- a/pvl/invoke.py Fri Dec 27 00:35:10 2013 +0200
+++ b/pvl/invoke.py Sat Mar 08 14:37:20 2014 +0200
@@ -2,8 +2,9 @@
Invoke external commands, with python kwargs -> options mangling.
"""
+import logging
+import os
import subprocess
-import logging
log = logging.getLogger('pvl.invoke')
@@ -16,7 +17,7 @@
def __str__ (self) :
return "{self.cmd} failed ({self.exit}): {self.error}".format(self=self)
-def invoke (cmd, args, stdin=None) :
+def invoke (cmd, args, stdin=None, setenv=None) :
"""
Invoke a command directly.
@@ -45,7 +46,14 @@
io = subprocess.PIPE
input = None
- p = subprocess.Popen([cmd] + args, stdin=io, stdout=io, stderr=io)
+ if setenv :
+ env = dict(os.environ)
+ env.update(setenv)
+
+ else :
+ env = None
+
+ p = subprocess.Popen([cmd] + list(args), stdin=io, stdout=io, stderr=io, env=env)
# get output
# returns None if not io