gpt4 book ai didi

Python OSError : [Errno 2]

转载 作者:IT老高 更新时间:2023-10-28 21:43:52 25 4
gpt4 key购买 nike

我有以下代码试图在 Linux 中启动下面的每个“命令”。如果两个命令中的任何一个因任何原因崩溃,该模块会尝试保持每个命令都运行。

#!/usr/bin/env python
import subprocess

commands = [ ["screen -dmS RealmD top"], ["screen -DmS RealmD top -d 5"] ]
programs = [ subprocess.Popen(c) for c in commands ]
while True:
for i in range(len(programs)):
if programs[i].returncode is None:
continue # still running
else:
# restart this one
programs[i]= subprocess.Popen(commands[i])
time.sleep(1.0)

执行代码时会抛出以下异常:

Traceback (most recent call last):
File "./marp.py", line 82, in <module>
programs = [ subprocess.Popen(c) for c in commands ]
File "/usr/lib/python2.6/subprocess.py", line 595, in __init__
errread, errwrite)
File "/usr/lib/python2.6/subprocess.py", line 1092, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory

我想我遗漏了一些明显的东西,有人能看出上面的代码有什么问题吗?

最佳答案

使用 ["screen", "-dmS", "RealmD", "top"]而不是 ["screen -dmS RealmD top"] .

也可以使用 screen 的完整路径.

关于Python OSError : [Errno 2],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/901982/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com