I am trying:
import subprocess
subprocess.call(["file.sh"])
But I keep getting:
Traceback (most recent call last):
File "project.py", line 85, in <module>
subprocess.call(["file.sh"])
File "/usr/local/lib/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/local/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/local/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
However when I try and run the script from the shell bash file.sh
it works. So I'm confused as to why it doesn't work?
I am not committed to using subprocess so if there are other options please let me know.
The call
function of the subprocess
package runs the command specified in arg as a list of strings (to simplify).
To call your file you have put in your script:
import subprocess
subprocess.call(["sh", "file.sh"])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.