On 04/12/2011, Tim Golden <m...@timgolden.me.uk> wrote: > > Someone raised issue13524 yesterday to illustrate that a > subprocess will crash immediately if an environment block is > passed which does not contain a valid SystemRoot environment > variable. ... > 2) Add a doc warning (ironically, considering the recent to-and-fro > on doc warnings in this very module).
There appears to already be such a warning, added because of a similar earlier bug: <http://bugs.python.org/issue3440> Really this is a problem with the subprocess api making a common case harder to do than necessary. If you read the documentation, you'll get it right, but that's not ideal: <http://sourcefrog.net/weblog/software/aesthetics/interface-levels.html> >From the bug, the problem with the reporter's code is he passes a dict with the one value he cares about as `env` to subprocess.Popen without realising that it will prevent the inheriting of the current environment. Your suggested fix for him also has an issue, it changes the environment of the parent process without resetting it. Instead you need something like: e = dict(os.environ) e['PATH_TO_MY_APPS'] = "path/to/my/apps" The bzrlib TestCase has a method using subprocess that provides an `env_changes` argument. With that, it's much easier to override or remove just one variable without accidentally clearing the current environment. Martin _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com