开发者

Inside python code, how do I run a .sh script?

开发者 https://www.devze.com 2023-02-07 00:58 出处:网络
Will it continue the code after it\'s run? Or开发者_如何学Python will it stop at that line until the script is done?Using subprocess.call is the easiest way. It will not return until the executed prog

Will it continue the code after it's run? Or开发者_如何学Python will it stop at that line until the script is done?


Using subprocess.call is the easiest way. It will not return until the executed program has terminated. Have a look at the other methods of the subprocess module if you need different behaviour.


import os
os.system('./script.sh')

python script won't stop until sh is finished


You can use os.system or subprocess.Popen or subprocess.call but when using subprocess methods make sure you use shell=True. And executing it via system call in all these methods is blocking. The python script will complete and then go the next step.

0

精彩评论

暂无评论...
验证码 换一张
取 消