我在通过python脚本启动npm命令时遇到问题。在
在Run npm commands using Python subprocess中,我发现以下方法应该有效:
subprocess.check_call('start npm run features:chrome:server', shell=True)
是的(!)。在
从文档(https://docs.python.org/3/library/subprocess.html)中,我读到subprocess.check_call
相当于run(..., check=True)
就像我以前用过的子流程.运行为了成功启动外部应用程序(newman),我尝试了以下操作:
^{pr2}$但最后却出现了一个错误:
Traceback (most recent call last):
File "test_differentiel.py", line 73, in <module>
subprocess.run("start npm run features:chrome:server")
File "C:\Users\a.joly\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 403, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\a.joly\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 707, in __init__
restore_signals, start_new_session)
File "C:\Users\a.joly\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 990, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] Le fichier spécifié est introuvable
你知道我为什么不能用吗子流程.运行? (顺便说一下,也不检查输出…)
正确的执行方式是
subprocess.run(['start', 'npm', 'run', 'features:chrome:server'], check=True)
subprocess.check_call('start npm run features:chrome:server', shell=True)
起作用是因为您调用了shell。您可以找到更多信息here。在subprocess.run("start npm run features:chrome:server", check=True, shell=True)
也可以。在相关问题 更多 >
编程相关推荐