Comment 10 for bug 709517

Revision history for this message
Loïc Minier (lool) wrote :

It's a bit trickier as I originally thought; this works:
env -u PATH python -c 'import os; os.environ["PATH"] = "foo"; from subprocess import Popen; Popen(["/usr/bin/env"]).wait()'|grep PATH

this doesn't:
env -u PATH python -c 'import os; os.environ["PATH"] = "foo"; from subprocess import Popen; Popen(["env"]).wait()'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.6/subprocess.py", line 623, in __init__
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1141, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

because Python uses the real os.environ when running / locating the command to Popen, so we should either ensure that os.environ is sane in some bootstrap code, or we should resolve all commands that we pass to Popen() ourselves after fixing the PATH.