在安装了32位python 2.7的64位系统中,我尝试执行以下操作:
import subprocess
p = subprocess.call('dir', shell=True)
print p
Run Code Online (Sandbox Code Playgroud)
但这给了我:
Traceback (most recent call last):
File "test.py", line 2, in <module>
p = subprocess.call('dir', shell=True)
File "C:\Python27\lib\subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 709, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 957, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Run Code Online (Sandbox Code Playgroud)
如果我在终端做...
dir
Run Code Online (Sandbox Code Playgroud)
...当然会打印当前文件夹内容.
我试图将shell参数更改为shell = False.
编辑:其实我不能在路径上调用任何可执行文件subprocess.call().该声明p = subprocess.call('dir', shell=True)在另一台机器上工作正常,我认为它是相关的.
如果我做
subprocess.call('PATH', shell=True)
Run Code Online (Sandbox Code Playgroud)
然后我明白了
Traceback (most …Run Code Online (Sandbox Code Playgroud)