Running bash script from within python

前端 未结 7 889
死守一世寂寞
死守一世寂寞 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:16

    Actually, you just have to add the shell=True argument:

    subprocess.call("sleep.sh", shell=True)
    

    But beware -

    Warning Invoking the system shell with shell=True can be a security hazard if combined with untrusted input. See the warning under Frequently Used Arguments for details.

    source

提交回复
热议问题