我在通过python脚本启动npm命令时遇到了问题。
在使用Python子进程运行npm命令中,我发现以下内容应该有效:
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)
正如我以前使用subprocess.run成功地启动外部应用程序(newman)一样,我尝试了以下操作:
subprocess.run("start npm run features:chrome:server", check=True)但结果却是一个错误:
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吗?(顺便说一下,也不是check_output .)
发布于 2017-09-13 13:18:34
正确的执行是subprocess.run(['start', 'npm', 'run', 'features:chrome:server'], check=True)
subprocess.check_call('start npm run features:chrome:server', shell=True)之所以有效,是因为您调用了shell。进一步的信息,您可以找到这里。
subprocess.run("start npm run features:chrome:server", check=True, shell=True)也应该能工作。
https://stackoverflow.com/questions/46198462
复制相似问题