Passing environment variable to "subprocess" causes failure

MRAB google at mrabarnett.plus.com
Tue Feb 3 21:44:27 EST 2009


davidgould at davidgould.com wrote:
 > I'm attempting to run subprocess and passing in an environment
 > variable. When I do this the child process fails with an error. When I
 > don't pass an environement variable it runs fine.
 >
 > BTW Running this code under Windows XP with Python 2.6.1
 >
 > 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
 >
 > Code B:
 >
 > p = subprocess.Popen( ['python', '-V'] )
 > print p.communicate()[0]
 > print p.returncode
 >
 > Output:
 >
 > Python 2.6.1
 > 0
 >
 > Any idea why passing an environment variable causes it to fail?
 > Thanks.
 >
Are you sure it's not the path within the dict you're passing that's wrong?



More information about the Python-list mailing list