python - 无法使用 subprocess.Popen() 运行进程

标签 python multiprocessing

我有一个从 python 程序运行的命令

python test.py arg1 arg2 

如果我使用

运行它
os.system("python test.py arg1 arg2")

它运行。

我想使用 subprocess.Popen() 但是当我这样做的时候

subprocess.Popen("python test.py arg1 arg2")

出现如下错误

raise child_exception
OSError: [Errno 2] No such file or directory

有什么想法吗?

非常感谢

最佳答案

如果参数为 Popen是一个字符串,它会尝试以 'sh <argument>' 的形式执行它,所以在你的情况下它变成了 'sh python test.py arg1 arg2'这显然是错误的。您可以向它传递一个列表(如 twall 建议的那样),或指定 shell=True范围。下一个应该工作:

subprocess.Popen("python test.py arg1 arg2", shell=True)

关于python - 无法使用 subprocess.Popen() 运行进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9735181/

相关文章:

python - 如何识别与查询图像模板匹配的图像中不同颜色的对象?

Python 2.7 多重处理

当我们运行许多任务时,python 多处理池不起作用

mysql - Perl、子项和共享数据

python - 在 Python-3.x 中使用最大 CPU 功率进行多处理

Python MySQLdb : creating database and filling table

python - 如何计算滚动窗口中数据框的列中相同实例的数量

python - 捕获内置异常(而不是自定义异常)

python - 在 python 的 tkinter 中,我怎样才能制作一个标签,这样你就可以用鼠标选择文本?

Python3 通过多处理并行化作业