在 Python 脚本中等待进程完成

wait a process to finish in Python script

我正在为 Windows 上的 运行 几个可执行文件编写一个 Python 脚本。我需要等待一个程序完成才能开始下一个程序。

所以脚本会是这样的

1: launch a.exe
2: wait till a.exe finishes running
3: launch b.exe
4: wait till b.exe finishes 

有人知道如何让脚本在 Python 内等待进程完成吗?

谢谢

如果您希望等待启动过程,只需使用 subprocess.call() 即可。此方法执行 args 中的命令并等待它完成。有关参考,请参阅 this

import subprocess
subprocess.call(('someprog.exe', str(i)))