在Python脚本中,我试图执行以下事件序列:
打开命令窗口并运行程序。完成后,将输出一个文本文件。
创建该文本文件后,关闭程序。
发生这种情况后,使用文本文件作为输入运行新程序
这是我到目前为止的内容:
subprocess.popen(['cmd','/c',r'programThatRuns.exe'])
subprocess.wait() # ? subprocess.check_call()? kill?
subprocess.popen(['cmd','/c',r'otherProgramThatRuns.exe'])
所以我想我真的停留在第二行
python大神给出的解决方案
您必须在子进程中应用“等待”,即
o = subprocess.popen(['cmd','/c',r'programThatRuns.exe'])
o.wait()
subprocess.popen(['cmd','/c',r'otherProgramThatRuns.exe'])
或者您使用check_call