. Advertisement .
. Advertisement .
As advised, I used some code samples in another forum, but it could not improve the problem. My question is the “oserror: [errno 8] exec format error” in python – how to solve it? The command line is:
import subprocess Out = subprocess.Popen(['/usr/local/bin/script', 'hostname = ', 'actual server name', '-p', 'LONGLIST'],shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
and the result:
OSError: [Errno 8] Exec format error
What does the message mean? Can you advise me to fix it? If you have other better answers, leave them in the answer box below.
The cause: The error because at the top of the shell script has no shebang line.
If you run the command in the shell, there is no error. By default,
subprocess.check output()does not run the shell; no subprocess functions run the shell unless asked clearly.
Solution: You should do the ways like this:
/bin/bashat the start of the command or the faulty file
#!/bin/shlike in a first-line
OSError: [Errno 8] Exec format errorcan occur if you don’t have a shebang line at top of your shell script, and you try to execute the script directly. This is an example of the problem:
You can fix it by adding the shebang, e.g., to a shell script; add
#!/bin/shto the top of your script.
exit 0with no errors
Shell parses the command-line on POSIX systems. Your script will not see any spaces around
=, e.g. if
Then, run it in the shell
Note: is not allowed around
'='. To escape the redirection metacharacters
<>, I have added quotes around
shell=True. You don’t have to escape
<>, as no shell is running.
"Exec format error"could indicate that your
scriptis not in the correct format. Run:
Find out more. Compare the architecture to the output of: