【发布时间】:2017-02-15 09:08:05
【问题描述】:
这个问题不是重复的
Communicate multiple times with a process without breaking the pipe?
该问题已解决,因为它的用例允许一起发送输入,但如果您的程序是交互式的(如此处的用例所示),则情况并非如此。
文件subprocess.Popen 说:
communicate(input=None)
Interact with process: Send data to stdin. Read data from stdout
and stderr, until end-of-file is reached. Wait for process to
terminate. ...
是否可以在子进程终止之前与其进行多次通信,例如与终端或网络套接字?
例如,如果子进程是bc,则父进程可能希望根据需要向其发送不同的输入进行计算。由于发送到bc 的输入可能取决于用户输入,因此不可能一次发送所有输入。
【问题讨论】: