为什么Python子进程可以运行不在路径中的命令?

时间:2015-12-22 13:41:43

标签: python windows cmd

我想使用Python的subprocess.check_output检查命令python是否在PATH及其版本中。有趣的是check_output能够运行命令python,即使它不在PATH中:

C:\Users\Aivar\Desktop>set PATH=blahblah

C:\Users\Aivar\Desktop>python --version
'python' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\Aivar\Desktop>c:\python35\python -c ^
More? "import subprocess; ^
More? print(subprocess.check_output(['python', '--version']))"
b'Python 3.5.1\r\n'

C:\Users\Aivar\Desktop>c:\python35\python -c ^
More? "import os; print(os.environ['PATH'])"
blahblah

有人可以解释发生了什么吗?

0 个答案:

没有答案