--- a/pvl/invoke.py Sun Jun 15 19:43:13 2014 +0300
+++ b/pvl/invoke.py Fri Jun 20 15:08:24 2014 +0300
@@ -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