【问题标题】:Get output from program into Ruby processing从程序中获取输出到 Ruby 处理中
【发布时间】:2016-10-11 23:09:47
【问题描述】:

我正在使用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。

【问题讨论】:

    标签: ruby linux processing


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多