【发布时间】:2017-08-08 14:27:33
【问题描述】:
我有一个运行输入流的 FORTRAN 程序。所以通常我使用“program.exe 输出”命令来执行程序。但是,我想在python中异步运行程序。
我试过了:
input = open("Input", 'rb').read()
running_procs = [Popen(['program.exe'], stdout=PIPE, stdin=PIPE, stderr=PIPE)]
while running_procs:
for proc in running_procs:
retcode = proc.poll()
if retcode is not None: # Process finished.
running_procs.remove(proc)
break
else: # No process is done, wait a bit and check again.
proc.stdin.write(input)
time.sleep(.1)
continue
# Here, `proc` has finished with return code `retcode`
if retcode != 0:
"""Error handling."""
print(proc.stdout)
不知道是不是
proc.stdin.write(input)
这将对输入流进行写入输入。
请帮忙。
【问题讨论】:
标签: python input stream subprocess