写了一个Python代码,用subprocess调用外部exe程序,这个程序会监控文件,然后给出相关的输出,问题是,在subprocess用管道重定向后,exe里的输出是缓存在,只有输出一定数据量时才会传到管道中,如何让subprocess里的管道无缓存运行? 虽然subprocess的Popen里有个buffersize项,但是设成0和1都没用,不知有没有谁遇到过这个问题,求解!!!!!
1
dreampuf Oct 25, 2013
不想自己维护buf定期输出就用python-sh模块
|
2
stevenyou Oct 25, 2013
定时调用flush(). 还有种方法
http://stackoverflow.com/questions/1606795/catching-stdout-in-realtime-from-subprocess 提到用pexpect |
3
clouder Oct 25, 2013
fd=os.poopen(cmd)
print fd.read() fd.close() |
4
lixm Oct 25, 2013
non-block IO就可以了, 可以参考这个 https://gist.github.com/7148531
|
5
emptyhua Oct 25, 2013
|
6
xierch Oct 25, 2013
这是得在 exe 里调用 flush 吧..?
|
8
tommark OP |
9
wynemo Oct 26, 2013
其实stdout=sys.stdout 应该就可以了吧。。。
|