Path not working with CreateProcess
OLD project page for the Python extensions for Windows
Brought to you by:
mhammond
The path in the environment doesn't seem to get through when using win32process.CreateProcess.
For example:
>>> import win32process
>>> si = win32process.STARTUPINFO()
# This works.
>>> win32process.CreateProcess(r'C:\Program Files\Perforce\p4.exe', 'p4.exe info', None, None, 1, 0, {'PATH': r'C:\Program Files\Perforce'}, None, si)
(<PyHANDLE at 36409480 (168)>, <PyHANDLE at 36409504 (172)>, 1152, 5672)
>>> Perforce client error:
Connect to server failed; check $P4PORT.
TCP connect to perforce-rwc:1666 failed.
No such host is known.
# This doesn't
>>> win32process.CreateProcess(r'p4.exe', 'p4.exe info', None, None, 1, 0, {'PATH': r'C:\Program Files\Perforce'}, None, si)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pywintypes.error: (2, 'CreateProcess', 'The system cannot find the file specified.')
Using None for the environment yields the same results. I ran into this issue with buildbot, which uses twisted, which uses pywin32. Here's a discussion on the buildbot mailing list where someone else ran into the issue:
http://sourceforge.net/p/buildbot/mailman/message/23639877/
The fix is to explicitly specify the executable path, so it's not a huge priority, but I thought I'd mention it.
The mailing list discussion seems to indicate that it's related to spaces in the path.
I believe this is just how CreateProcess works - the environment, including PATH, is the environment for the new process - it's not applied to the first argument of CreateProcess as that is in the parent process - ie, the child process hasn't yet been created at the time this PATH would need to have been taken into account.
The docs for CreateProcess say:
"The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. This parameter must include the file name extension; no default extension is assumed."
So I believe your expectation of how CreateProcess handles this first arg is wrong.
I see, thank you for clearing that up for me!