Python 使用不同的线程将输入和输出发送到exe文件

Python 使用不同的线程将输入和输出发送到exe文件,python,multithreading,subprocess,pipe,Python,Multithreading,Subprocess,Pipe,我正在尝试编写一个脚本,该脚本发送文本并从给定的.exe文件中获取输出。 .exe文件将脚本发送到其输入的内容发送到其输出。 发送输入和读取输出应使用不同的线程完成 import subprocess proc=subprocess.Popen(['file.exe'],stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stdin=subprocess.PIPE) stdout, stdin = proc.communicate() proc.

我正在尝试编写一个脚本,该脚本发送文本并从给定的
.exe
文件中获取输出。
.exe
文件将脚本发送到其输入的内容发送到其输出。 发送输入和读取输出应使用不同的线程完成

import subprocess
proc=subprocess.Popen(['file.exe'],stderr=subprocess.STDOUT, stdout=subprocess.PIPE, stdin=subprocess.PIPE)

stdout, stdin = proc.communicate()
proc.stdin.write(text)
proc.stdin.close()
result=proc.stdout.read()
print result
现在我找不到一种使用单独线程进行通信的方法


非常感谢您的指导和帮助。

也许您可以试试这样的方法。在主线程中发送输入,在另一个线程中获取输出

class Exe(threading.Thread):
def __init__(self, text=""):
    self.text = text
    self.stdout = None
    self.stderr = None
    threading.Thread.__init__(self)

def run(self):
    p = subprocess.Popen(['file.exe'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
    self.stdout, self.stderr = p.communicate(self.text)

text = "input"
exe = Exe(text)
exe.start()
exe.join()
print exe.stdout
return 0