Question
Asked By – user1638145
I have a problem with the following code:
callBash.py:
import subprocess
print "start"
subprocess.call("sleep.sh")
print "end"
sleep.sh:
sleep 10
I want the “end” to be printed after 10s. (I know that this is a dumb example, I could simply sleep within python, but this simple sleep.sh file was just as a test)
Now we will see solution for issue: Running bash script from within python
Answer
Making sleep.sh executable and adding shell=True
to the parameter list (as suggested in previous answers) works ok. Depending on the search path, you may also need to add ./
or some other appropriate path. (Ie, change "sleep.sh"
to "./sleep.sh"
.)
The shell=True
parameter is not needed (under a Posix system like Linux) if the first line of the bash script is a path to a shell; for example, #!/bin/bash
.
This question is answered By – James Waldby – jwpat7
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0