[issue15451] PATH is not honored in subprocess.Popen in win32

2012-07-25 Thread Grissiom Gu

New submission from Grissiom Gu :

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
sys.exit(rv)
==
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 
<http://bugs.python.org/issue15451>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15451] PATH is not honored in subprocess.Popen in win32

2012-07-28 Thread Grissiom Gu

Grissiom Gu added the comment:

Thank you for everyone participated in this issue. I learnt a lot from you.

But I observe that the same script(with proper modification of file names) 
works very well under Linux. After I dive into the source code, I found Python 
use execvpe to invoke the child process which _will_ use the PATH variable to 
search the executable.

So I think this is a inconsistent behavior at least. So I think we should 
either notify the user that this API is inconsistent or just fix the Popen call 
in windows. Prepending the new PATH to the env of current process and than call 
CreateProcess is just a patch within 10 lines, I think.

--

___
Python tracker 
<http://bugs.python.org/issue15451>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com