Eryk Sun <eryk...@gmail.com> added the comment:

In a patch review [1] for issue 24505, I had a discussion with Toby Tobkin 
about extending the behavior of shutil.which() on Windows. This was to match 
the behavior of the CMD shell, including securing the search path via 
NeedCurrentDirectoryForExePath, searching for the exact filename, and 
implementing a real execute-access check. 

CMD won't directly execute a file that lacks execute access -- even a script or 
data file. We can implement this with a real implementation of os.access() that 
checks file security, for which there's an existing issue. (My previous 
suggestion to use CreateProcess and AssocQueryString to check for execute 
access was over the top. At the time I was thinking about building out support 
for a high-level shutil.execute, but it's out of scope here.)

Note that CMD will only try to execute an extensionless file if "." is in 
PATHEXT. (In the Windows file namespace, "name" and "name." are equivalent.) 
This obviously works for PE binaries, but we can also define an association for 
"." in the registy, which is useful for extensionless script files. Just 
associate "." files with a launcher that tries CreateProcess and falls back on 
a shebang line.

[1]: 
https://web.archive.org/web/20170619131224/http://bugs.python.org:80/review/24505/diff/16179/Lib/shutil.py

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31405>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to