質問

通信によってプロセスが強制終了されるのはなぜですか?インタラクティブなプロセスが必要ですが、通信で何らかの処理が行われるため、プロセス内で raw_input を受け取ることができなくなります。

from sys import stdin 
from threading import Thread
from time import sleep

if __name__ == '__main__':
    print("Still Running\n")
    x = raw_input()    
    i = 0
    while ('n' not in x ) :
        print("Still Running " + str(i) + " \r\n")
        x = raw_input()
        i += 1

    print("quit")



print(aSubProc.theProcess.communicate('y'))
print(aSubProc.theProcess.communicate('y'))

例外!

self.stdin.write(input)
ValueError: I/O operation on closed file
役に立ちましたか?

解決

communicate そして wait の方法 Popen オブジェクトを閉じます。 PIPE プロセスが戻った後。プロセスとの通信を維持したい場合は、次のようなことを試してください。

import subprocess
proc = subprocess.Popen("some_process", stdout=subprocess.PIPE, stdin=subprocess.PIPE)
proc.stdin.write("input")
proc.stdout.readline()
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top