Ruby 有没有大神知道怎么将 stdout 标准输出实时重定向到一个界面的文本框中

whulanqier · June 09, 2013 · Last by nine replied at December 18, 2014 · 4342 hits

用 fxruby 做了一个界面,运行程序时 puts 的打印信息都在标准输出界面上,想让信息实时显示在界面的文本框内,求指教

可以写到一个文件里吧,再读文件,可否?

先把 stdout 替换成管道

watch_reader, $stdout = IO.pipe

然后用 FXApp::addInput(watch_reader.fileno) 去检查读事件

http://rubydoc.info/gems/fxruby/Fox/FXApp:addInput

再在回调中读出文本,append 到文本框中

谢谢楼上的

You need to Sign in before reply, if you don't have an account, please Sign up first.