[docs] [issue20927] Different behaviour on Posix and Windows when using subprocess.Popen(..., cwd=path)

Eric V. Smith report at bugs.python.org
Mon Mar 17 15:06:23 CET 2014


Eric V. Smith added the comment:

I think the 2.7 documentation is correct: the current directory when the call is made, and not cwd, is included in the search path. I'd suggest specifying args as ["c:\\python33\\workspace\\plink.exe"].

I think I may have mislead you earlier on the search path. The Windows call is:
CreateProcess(lpApplicationName, lpCommandLine, <other stuff>, lpCurrentDirectory, <other stuff>)

The first parameter to Popen ("args") becomes lpCommandLine. The "executable" parameter to Popen, which you're not setting, becomes lpApplicationName. So, you're calling CreateProcess(NULL, "plink.exe, ..., lpCurrentDirectory="c:\\python33\\workspace").

In this case, .exe would be added if missing. But, the search path rules seem to not include the directory pointed to by lpCurrentDirectory (aka cwd).

So I think this would work:
subprocess.Popen(["c:\\python33\\workspace\\plink.exe"], stdout=subprocess.PIPE, cwd="c:\\python33\\workspace")
or
subprocess.Popen(["plink"], executable="c:\\python33\\workspace\\plink.exe", stdout=subprocess.PIPE, cwd="c:\\python33\\workspace")

Unfortunately, I don't have a copy of 3.x on my Windows machine to test with.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20927>
_______________________________________


More information about the docs mailing list