Python OSError: [Errno 2] [英] Python OSError: [Errno 2]

查看:33
本文介绍了Python OSError: [Errno 2]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码试图在 Linux 中启动下面的每个命令".模块会尝试让 2 个命令中的每一个保持运行,如果其中一个因任何原因崩溃.

I have the following code that is attempting to start each of the "commands" below in Linux. The module attempts to keep each of the 2 commands running if either should crash for whatever reason.

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

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

Upon executing the code the following exception is thrown:

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

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

I think I'm missing something obvious, can anyone see what's wrong with the code above?

推荐答案

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

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

Maybe also use the complete path to screen.

这篇关于Python OSError: [Errno 2]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆