【发布时间】:2020-03-29 06:20:09
【问题描述】:
我在 Windows 10 64 位上使用 Python 2.7.14。我需要使用
subprocess.call
但如果我不通过 shell=True,它每次都会失败。根据python doc,不应使用 shell=True。我也想知道为什么会失败。
python
ActivePython 2.7.14.2717 (ActiveState Software Inc.) based on
Python 2.7.14 (default, Dec 15 2017, 16:31:45) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> subprocess.call(['date'])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
但是当使用 shell=True 运行时,它运行良好
>>> subprocess.call(['date'],shell=True)
The current date is: Wed 12/04/2019
Enter the new date: (mm-dd-yy)
我也在 mac 上试过,没有 shell=True
的 subprocess.call 运行良好请帮忙。
【问题讨论】:
标签: python windows python-2.7 cmd subprocess