【问题标题】:Is it possible to solve with python to run two executable and they can communicate each other (stdin/stdout)?是否可以用 python 解决运行两个可执行文件并且它们可以相互通信(stdin/stdout)?
【发布时间】:2019-07-11 18:23:21
【问题描述】:

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

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

(其中 A.exe 包含 print/scanf 对,B.exe 包含 scanf/printfs。)

【问题讨论】:

标签: python redirect stdout stdin


【解决方案1】:

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

(output, error) = A.communicate(input="send to a")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-07
    • 2022-06-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多