mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
gh-101283: Improved fallback logic for subprocess with shell=True on Windows (GH-101286)
This commit is contained in:
parent
de3669ebcb
commit
23751ed826
3 changed files with 58 additions and 1 deletions
|
@ -1480,7 +1480,21 @@ class Popen:
|
|||
if shell:
|
||||
startupinfo.dwFlags |= _winapi.STARTF_USESHOWWINDOW
|
||||
startupinfo.wShowWindow = _winapi.SW_HIDE
|
||||
comspec = os.environ.get("COMSPEC", "cmd.exe")
|
||||
if not executable:
|
||||
# gh-101283: without a fully-qualified path, before Windows
|
||||
# checks the system directories, it first looks in the
|
||||
# application directory, and also the current directory if
|
||||
# NeedCurrentDirectoryForExePathW(ExeName) is true, so try
|
||||
# to avoid executing unqualified "cmd.exe".
|
||||
comspec = os.environ.get('ComSpec')
|
||||
if not comspec:
|
||||
system_root = os.environ.get('SystemRoot', '')
|
||||
comspec = os.path.join(system_root, 'System32', 'cmd.exe')
|
||||
if not os.path.isabs(comspec):
|
||||
raise FileNotFoundError('shell not found: neither %ComSpec% nor %SystemRoot% is set')
|
||||
if os.path.isabs(comspec):
|
||||
executable = comspec
|
||||
|
||||
args = '{} /c "{}"'.format (comspec, args)
|
||||
|
||||
if cwd is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue