execute_process ignores PATHEXT environment variable
On Windows, when a command is executed in CMD or PowerShell with the file extension omitted, the file extensions in PATHEXT
are appended when searching for commands in the directories specified by PATH
. Because of this, some cross-platform command-line scripts ship their Unix versions with no file extension and a shebang to select the interpreter, and their Windows versions with a file extension so the interpreter can be picked by the registry, then calling the command with no extension works on all platforms.
In such a situation, execute_process
only seems to append the .exe
extension, which will either pick a different executable to CMD/PowerShell if an alternative is available on the PATH, or generate a The system cannot find the file specified error message.
It may be expected that execute_process
tries all the extensions in PATHEXT
in each directory in PATH
.
This may also not be desirable in some situations, e.g. if thing.py
is earlier on the PATH
than thing.exe
and the latter is desired, so maybe should be implemented as an optional argument to execute_process
which enables this behaviour when running on Windows.
Related to #9879