Passing environment variable to "subprocess" causes failure

Miki miki.tebeka at gmail.com
Tue Feb 3 22:34:15 EST 2009


> Code A:
>
> p = subprocess.Popen( ['python', '-V'], env={ 'PYTHONPATH': 'C:/
> Documents and Settings/David Gould/workspace/DgTools/Common/Trunk/
> Source' } )
> print p.communicate()[0]
> print p.returncode
>
> Output:
>
> None
> -1072365564
My *guess* is that since PATH is not in the environment you're
passing, the shell can't find the python interpreter.
Try:
from os import environ
from subprocess import Popen, PIPE
env = environ.copy()
# Warning: override existing PYTHONPATH
env["PYTHONPATH"] = "C:/Documents and Settings/David Gould/workspace/
DgTools/Common/Trunk/Source"
p = = subprocess.Popen(['python', '-V'], env=env, stdout=PIPE)
print p.communicate()
print p.returncode

HTH,
--
Miki <miki.tebeka at gmail.com>
http://pythonwise.blogspot.com



More information about the Python-list mailing list