Python subprocess.call在没有shell = True的Windows上失败。

问题描述 投票:0回答:1
我正在Windows 10 64bit上使用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上尝试过,subprocess.call在没有

shell = True

的情况下也可以正常运行请帮助。

我正在Windows 10 64bit上使用Python 2.7.14。我需要使用subprocess.call,但是如果我不通过shell = True,它每次都会失败。根据python文档,不应使用shell = True。另外我...

python windows python-2.7 cmd subprocess
1个回答
0
投票
date不是可执行文件,而是builtin function of cmd.exe。您不能在外壳之外使用它。
© www.soinside.com 2019 - 2024. All rights reserved.