Yesterday, I wrote and ran a python script
which executes a shell
using subprocess.Popen(command.split())
where command is string whic
The error message suggests that the external program is not a valid executable.
As @tripleee said, there is an issue executing your script. Make sure:
See also: Why is '#!/usr/bin/env python' supposedly more correct than just '#!/usr/bin/python'?
Following statement worked for me
subprocess.Popen(['sh','my_script.sh'])
It is recommended to install the package binfmt-support to help the system better recognize the scipts. It helps regardless of whether they have a shebang line.
The error is because the executables are not given in the prescribed format for subprocess to execute it.
example:
shell_command1 = r"/path/to/executable/shell/file"
shell_command2 = r"./path/to/executable/shell/file"
subprocess.call(shell_command1)
or subprocess.Popen(shell_command1)
will not be able to run shell_command1 because subprocess needs an executable command like (mailx, ls, ping, etc.) or executable script like shell_command2 or you need to specify command like this
subprocess.call(["sh", shell_command1])
subprocess.Popen(["sh", shell_command1])
but however, you can use os.system()
or os.Popen()
as well
I solved this by putting this line at the top of the called shell script:
#!/bin/sh
That will guarantee that the system always uses the correct interpreter when running your script.