Running bash script from within python

前端 未结 7 913
死守一世寂寞
死守一世寂寞 2020-11-27 11:50

I have a problem with the following code:

callBash.py:

import subprocess
print \"start\"
subprocess.call(\"sleep.sh\")
print \"end\"         


        
7条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 12:01

    Make sure that sleep.sh has execution permissions, and run it with shell=True:

    #!/usr/bin/python
    
    import subprocess
    print "start"
    subprocess.call("./sleep.sh", shell=True)
    print "end"
    

提交回复
热议问题