This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eryksun
Recipients asvetlov, chris.jerdonek, cvrebert, docs@python, eryksun, ned.deily, paul.moore, pepalogik, python-dev, steve.dower, tim.golden, wolma, zach.ware
Date 2017-02-04.14:55:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1486220152.61.0.134793874137.issue15533@psf.upfronthosting.co.za>
In-reply-to
Content
The Unix implementation of subprocess.Popen follows the behavior of os.execvpe, which is an outlier. Other execvpe implementations, such as the one added to glibc in 2009, search PATH in the current environment instead of the passed environment. As such, and given the natural expectations of a Windows programmer, I do not see the current behavior of the Windows implementation as incorrect. It's a documentation bug.

On a related note, the Popen documentation for Windows should also mention that defining the environment variable NoDefaultCurrentDirectoryInExePath removes the current directory from the executable search path, in both CreateProcess and cmd.exe (i.e. w/ shell=True). This feature was introduced in Windows Vista, so it applies to Python 3.5+. 

> Python actually executes the program, but argv[0] is inconsistent with
> cwd. Imagine that the called program wants to resolve its own path:
> It joins cwd and argv[0] and gets 
> "C:\Users\Jenda\Bug reports\Python\subprocess\subdir\subdir\print_argv+cwd.exe"

A Windows program would call GetModuleFileName with hModule as NULL, which returns the path of the process executable. There's also the pseudo-environment variable __APPDIR__. 

Using argv[0] from the command line would be unreliable. For example:

    >>> _ = run('"spam & eggs" /c echo %__APPDIR__%',
    ...         executable=os.environ['ComSpec'])
    C:\Windows\system32\

    >>> _ = run('"spam & eggs" -m calendar 2017 2',
    ...         executable=sys.executable)
       February 2017
    Mo Tu We Th Fr Sa Su
           1  2  3  4  5
     6  7  8  9 10 11 12
    13 14 15 16 17 18 19
    20 21 22 23 24 25 26
    27 28
History
Date User Action Args
2017-02-04 14:55:52eryksunsetrecipients: + eryksun, paul.moore, tim.golden, ned.deily, cvrebert, asvetlov, chris.jerdonek, docs@python, python-dev, zach.ware, steve.dower, pepalogik, wolma
2017-02-04 14:55:52eryksunsetmessageid: <1486220152.61.0.134793874137.issue15533@psf.upfronthosting.co.za>
2017-02-04 14:55:52eryksunlinkissue15533 messages
2017-02-04 14:55:52eryksuncreate