Running bash script from within python

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

    If someone looking for calling a script with arguments

    import subprocess
    
    val = subprocess.check_call("./script.sh '%s'" % arg, shell=True)
    

    Remember to convert the args to string before passing, using str(arg).

    This can be used to pass as many arguments as desired:

    subprocess.check_call("./script.ksh %s %s %s" % (arg1, str(arg2), arg3), shell=True)
    
    0 讨论(0)
提交回复
热议问题