尝试循环时,Python cmd脚本挂起

时间:2018-05-30 07:39:46

标签: python batch-file testing cmd automation

我正在尝试制作一个python脚本,一个接一个地使用不同的配置多次运行批处理文件。我遇到的问题是我正在尝试等待它等待运行完成然后运行另一个,但cmd挂起并且不让第二个参数写入cmd。仅使用cmd手动运行批处理文件时,它不会这样做。所以不要真正理解问题所在。我是Python的新手,所以欢迎提出如何改进这个脚本的建议:

import subprocess

# open commandline
subprocess.Popen([r"cmd"])

# Run every test 5 times.
# Wait for a single run to finish before running another one

for x in xrange(0, 5):
    subprocess.run(["batchfile.bat", "arg", "arg", "arg", "arg"])
    subprocess.Popen.wait(timeout=None)

for x in xrange(0, 5):
    subprocess.run(["batchfile.bat", "arg", "arg", "arg", "arg"])
    subprocess.Popen.wait(timeout=None)

编辑: 将subprocess.Popen()更改为subprocess.run()会挂起cmd消息,所以现在我只有等待进程再次启动的问题。更新了代码段。

0 个答案:

没有答案