Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python OSError: [Errno 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?

like image 958
Caedis Avatar asked May 23 '09 17:05

Caedis


People also ask

How do I fix Errno 2 in Python?

The Python FileNotFoundError: [Errno 2] No such file or directory error is often raised by the os library. This error tells you that you are trying to access a file or folder that does not exist. To fix this error, check that you are referring to the right file or folder in your program.

How do I fix FileNotFoundError Errno 2 No such file or directory in Python?

The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.

How do I fix No such file or directory error in Python?

To solve No Such File Or Directory Error in Python, ensure that the file exists in your provided path. To check all the files in the directory, use the os. listdir() method.

Can't open file Errno 2 No such file or directory?

The Python "FileNotFoundError: [Errno 2] No such file or directory" occurs when we try to open a file that doesn't exist in the specified location. To solve the error, move the file to the directory where the Python script is located if using a local path, or use an absolute path.


2 Answers

Use ["screen", "-dmS", "RealmD", "top"] instead of ["screen -dmS RealmD top"].

Maybe also use the complete path to screen.

like image 157
sth Avatar answered Sep 22 '22 09:09

sth


Only guess is that it can't find screen. Try /usr/bin/screen or whatever which screen gives you.

like image 41
Colin Burnett Avatar answered Sep 25 '22 09:09

Colin Burnett