如何使python等到批处理执行完成

问题描述 投票:0回答:1

Path =批处理文件的位置。(c:.... \ a.bat)

并且a.bat包含以下数据:START C:\ Python27 \ python.exe“C:..... \ test.py”

我有以下代码:

      my_process = subprocess.call(os.path.abspath(path), shell=True)

      text_file = open("output.txt",r)  # output.txt is batch file output

我希望代码应该等待批处理文件的执行,批处理文件的输出应该生成output.txt。后来text_file = open(“output.txt”,r)应该执行。

但是代码不会等待批处理文件执行,并且很快就会生成错误,即找不到output.txt。

python batch-file subprocess
1个回答
1
投票

感谢@MarkSetchell现在使用/ WAIT工作

© www.soinside.com 2019 - 2024. All rights reserved.