Print out the output of os.popen() without buffering in python

不羁的心 提交于 2019-12-05 21:47:25

The data is being buffered by ruby. Use something like

$stdout.flush

to make it flush. I'm not sure if that's the correct ruby command to do that.


Obligatory:

Use subprocess module. os.popen has been replaced by it.

import subprocess
import sys

cmd = ["ruby", "/Users/smcho/Desktop/testit.rb"]
p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
for line in iter(p.stdout.readline, ''):
    print line, 
    sys.stdout.flush() 
p.wait()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!