Fix Python – Running bash script from within python


Asked By – user1638145

I have a problem with the following code:

import subprocess
print "start""")
print "end"

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 file was just as a test)

Now we will see solution for issue: Running bash script from within python


Making 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 "" to "./".)

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