【问题标题】:Waiting on another python process to continue等待另一个 python 进程继续
【发布时间】:2019-09-26 10:55:19
【问题描述】:

Python 版本:Python 2.7.13

我正在尝试编写一个能够通过 *.txt 文件并启动批处理文件来执行特定测试的脚本。

下面的代码遍历输入文件,将字符串从“N”更改为“Y”,从而允许执行特定的测试。我正在创建一个 for 循环以遍历 *.txt 文件中的所有行并按顺序执行所有测试。但是,我的问题是我不想同时执行测试(如果我只是编写测试代码会发生这种情况)。

有没有办法等到初始测试完成后再启动下一个测试?

这是我目前所拥有的:

from subprocess import Popen
import os, glob

path = r'C:/Users/user1/Desktop/MAT'

for fname in os.listdir(path):
    if fname.startswith("fort"):
        os.remove(os.path.join(path, fname))

with open('RUN_STUDY_CHECKLIST.txt', 'r') as file:
    data = file.readlines()

ln = 4

ch = list(data[ln])
ch[48] = 'Y'
data[ln] = "".join(ch)

with open('RUN_STUDY_CHECKLIST.txt', 'w') as file:
    file.writelines(data)

matexe = Popen('run.bat', cwd=r"C:/Users/user1/Desktop/MAT")
stdout, stderr = matexe.communicate()

在这个特定的例子中,我将 *.txt 文件第 2 行中的“N”更改为“Y”,它将用作另一个 python 脚本的输入。

我不得不提一下,我想在不与任何提示交互的情况下执行此任务,我想执行脚本并让它运行(因为通过所有测试需要很长时间) .

最好的问候,

豪尔赫

【问题讨论】:

    标签: python-2.7 wait


    【解决方案1】:

    在进一步浏览了几个网站后,我设法找到了我的问题的解决方案。

    我用过:

    exe1 = subprocess.Popen(['python', 'script.py'])
    
    exe1.wait()
    

    我想发布答案以防万一这对任何人都有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 2016-08-09
      • 2018-05-28
      • 2020-05-07
      • 1970-01-01
      • 2016-08-16
      相关资源
      最近更新 更多