If sleep.sh has shebang #!/bin/sh and has the appropriate file permissions - run chmod u+rx sleep.sh to make sure it is in $PATH , then your code should work as it is:
import subprocess rc = subprocess.call("sleep.sh")
If the script is not in the PATH, then specify the full path to it, for example, if it is in the current working directory:
from subprocess import call rc = call("./sleep.sh")
If the script does not have shebang, then you need to specify shell=True :
rc = call("./sleep.sh", shell=True)
If the script does not have executable permissions and you cannot change it, for example, by running os.chmod('sleep.sh', 0o755) , you can read the script as a text file and pass a line instead of subprocess :
with open('sleep.sh', 'rb') as file: script = file.read() rc = call(script, shell=True)
jfs Mar 14 '14 at 21:35 2014-03-14 21:35
source share