从程序获取输出到Ruby处理

时间:2013-08-02 06:20:35

标签: ruby linux processing

我正在使用Ruby processing library

我想将程序的输出传输到我的代码中。例如,echo "hello" | rp5 run receiver.rb

在正常程序中,我知道我可以用

完成此任务
while $stdin.gets
  puts $_
  puts "Receiving!"
end

我知道在处理过程中,程序会不断循环draw函数。所以我尝试了这段代码,但它没有用,因为它冻结了puts $stdin.gets行。所以我知道管道不匹配一定是个问题,所以我要尝试使用命名管道,这样就不会有混淆。

def setup
    puts "setting up"
end

def draw
    puts "drawing"
    puts $stdin
    puts $stdin.gets
    puts "after gets"
    while $stdin.gets
        puts $_
        puts "Receiving!"
    end
    puts "done drawing"
end

任何建议都将不胜感激。我正在运行Ubuntu 12.04。

1 个答案:

答案 0 :(得分:0)

是的,名称管道工作。查看this example以帮助您入门并确保已加载最新版本的JRuby。