我正在尝试使用子进程打开另一个进程,该进程在我的主进程运行时应该是活动的。这个主进程会向该子进程发送一些命令。但是,当我使用管道与该子进程通信时,它还添加了一个eot(End Of Transmission)char,它通常为基于linux的os中的进程终止char。
my_subprocess = subprocess.Popen("python", shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
my_subprocess.stdin.write("print 2+2\n")
stdout, stderr = my_file.communicate()
my_subprocess.stdin.write("print 3+5\n")
第一个调用生成一个^ D,它是python shell的终止字符。因此,我得到这样的错误:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: I/O operation on closed file
有没有办法为此目的使用子进程?