Python OSError: [Errno 2]

18 浏览
0 Comments

Python OSError: [Errno 2]

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

#!/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 
    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

我觉得我可能漏掉了一些明显的东西,有人能看出上述代码有什么问题吗?

0