我想使用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
有人可以解释发生了什么吗?