有可能用python来解决运行两个可执行文件并且它们可以相互通信(stdin / stdout)吗?

问题描述 投票:0回答:1

我有两个可执行文件,例如A.exe,B.exe。是否可以使用python子进程popen将两个可执行文件通过stdin / stdout相互通信:

A = Popen("A.exe",...,stdin=B.stdout, stdout=PIPE)
B = Popen("B.exe",...,stdin=A.stdout, stdout=PIPE) ?

(其中A.exe包含printf / scanf对,而B.exe包含scanf / printf。)

python redirect stdout stdin
1个回答
0
投票

尝试Popen.communicate它需要一个参数input与文本发送到子进程并返回一个元组(stdout_data, stderr_data)

(output, error) = A.communicate(input="send to a")
© www.soinside.com 2019 - 2024. All rights reserved.