2017-03-17 18 views
0

私は入力ストリームを実行するFORTRANプログラムを持っています。だから私は通常 "program.exe <入力>出力"コマンドを使用してプログラムを実行します。しかし、私は非同期にpythonでプログラムを実行したい。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) 

これは、入力ストリームに書き込み入力を行います場合は知りません。

助けてください。

答えて

0

申し訳ありません申し訳ありませんが実際に私が尋ねた質問に関して多くの投稿がありました。

input = open("Input", 'rb').read() 

running_proc = Popen(['program.exe'], stdout=PIPE, stdin=PIPE, stderr=PIPE) 
out, err = running_proc.communicate(input=input) 
outfile = open("outfile.out", "w") 
outfile.write(out.decode()) 

はあなた

ありがとう
関連する問題