[New-bugs-announce] [issue15451] PATH is not honored in subprocess.Popen in win32

Grissiom Gu report at bugs.python.org
Thu Jul 26 02:57:10 CEST 2012

New submission from Grissiom Gu <chaos.proton at gmail.com>:

My system is 32 bit win7 and python is 2.7.2.

Sample code is here:
import os, sys

nenv = {}
nenv['PATH'] = 'C:\\Windows\\System32\\;e:\\projects\\teest\\python\\exe\\'
nenv['SystemRoot'] = 'C:\\Windows\\'

#os.putenv('PATH', nenv['PATH'])
import subprocess
proc = subprocess.Popen('test.bat', stdin=subprocess.PIPE, stdout=subprocess.PIPE,
    stderr=subprocess.PIPE, shell = False, env=nenv)
data, err = proc.communicate()
rv = proc.wait()

if data:
    print data
if err:
    print err
in E:\projects\teest\python I have two folders: 'exe/' have a bat file named 'test.bat' and a 'launch/' folder have the above script. When execute the above script, python yield "WindowsError: [Error 2]" which means could not find the executable.

However, if I un-comment the line "#os.putenv('PATH', nenv['PATH'])", it works like a charm. It seems _subprocess.CreateProcess does not honer the PATH.

FYI, if I use the CreateProcess of win32 extensions, thing works fine without the need to export PATH.

messages: 166447
nosy: Grissiom.Gu
priority: normal
severity: normal
status: open
title: PATH is not honored in subprocess.Popen in win32
type: behavior
versions: Python 2.7

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list