在python代码中,如何运行.sh脚本?

时间:2021-11-09 20:59:12

Will it continue the code after it's run? Or will it stop at that line until the script is done?

它会在运行后继续运行吗?或者它会在脚本停止直到脚本完成?

3 个解决方案

#1


10  

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.

使用subprocess.call是最简单的方法。在执行的程序终止之前,它不会返回。如果需要不同的行为,请查看子进程模块的其他方法。

#2


5  

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

python script won't stop until sh is finished

在sh完成之前,python脚本不会停止

#3


0  

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.

您可以使用os.system或subprocess.Popen或subprocess.call,但在使用子进程方法时,请确保使用shell = True。在所有这些方法中通过系统调用执行它是阻塞的。 python脚本将完成,然后进入下一步。

#1


10  

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.

使用subprocess.call是最简单的方法。在执行的程序终止之前,它不会返回。如果需要不同的行为,请查看子进程模块的其他方法。

#2


5  

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

python script won't stop until sh is finished

在sh完成之前,python脚本不会停止

#3


0  

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.

您可以使用os.system或subprocess.Popen或subprocess.call,但在使用子进程方法时,请确保使用shell = True。在所有这些方法中通过系统调用执行它是阻塞的。 python脚本将完成,然后进入下一步。