寻找等效的Windows命令(对于无缓冲控制台输出的Linux命令)

时间:2017-01-23 11:37:48

标签: python linux windows cmd stdout

这是一个简短的python脚本,它应该运行带有无缓冲输出的控制台应用程序test__2。

comm.py

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>

0 个答案:

没有答案