这是一个简短的python脚本,它应该运行带有无缓冲输出的控制台应用程序test__2。
import subprocess
cmd = ['/usr/bin/stdbuf', '-i0','-o0', '-e0', './test__2']
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=False)
p.stdin.flush()
p.stdout.flush()
x = b'1\n'
while True:
p.stdin.write(x)
x = p.stdout.readline()
print(x)
if p.poll() != None:
break
我需要等同于这一行:
cmd = ['/usr/bin/stdbuf', '-i0','-o0', '-e0', './test__2']
将在Windows上运行。
(有关更多背景信息,请参阅Python : communication with c++ command line program not working when using <cstdio>)