每当我运行此脚本时:
import subprocess
process = subprocess.Popen(['grunt', 'build'], stdout=subprocess.PIPE)
我一直都会遇到这个错误:
Traceback (most recent call last):
File "test_grunt_fail.py", line 3, in <module>
process = subprocess.Popen(['grunt', 'build'], stdout=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 710, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 958, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
但是,grunt
肯定已安装,因为我可以从命令行运行grunt build
而不会出现任何问题,并在程序中运行os.system("grunt build")
。
鉴于此,os.system()
为什么会在subprocess.Popen()
不起作用?