summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-02-08 23:44:06 (GMT)
committerGitHub <noreply@github.com>2023-02-08 23:44:06 (GMT)
commit51b079a2d6c9a7a852c04823ef4180c36eed682b (patch)
tree36d910658a1d30cf33813132b628cb05afbba650 /Lib/subprocess.py
parente8ce85de594e62c73db8d523408c9e1b720f0d0b (diff)
downloadcpython-51b079a2d6c9a7a852c04823ef4180c36eed682b.zip
cpython-51b079a2d6c9a7a852c04823ef4180c36eed682b.tar.gz
cpython-51b079a2d6c9a7a852c04823ef4180c36eed682b.tar.bz2
Update Lib/subprocess.py
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 9cadd1b..1f203bd 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -1480,7 +1480,23 @@ 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
+ else:
+ comspec = executable
+
args = '{} /c "{}"'.format (comspec, args)
if cwd is not None: