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