【问题标题】:how to make python to wait until batch execution get complete如何让python等到批处理执行完成
【发布时间】:2019-01-26 11:04:09
【问题描述】:

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

并且 a.bat 包含以下数据: 开始 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 的错误。

【问题讨论】:

  • START /WAIT 也许?

标签: python batch-file subprocess


【解决方案1】:

感谢@MarkSetchell,它适用于

START /WAIT

【讨论】:

    猜你喜欢
    • 2011-02-04
    • 2022-11-16
    • 2012-07-19
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 2012-10-14
    • 2018-12-11
    • 2019-08-21
    相关资源
    最近更新 更多