2

这是用于开发机器和测试目的。我正在尝试启动一个启动服务器的脚本,然后在输出满足条件时忽略它。该过程没有结束,所以我不能使用反引号。我将-QUIT独立地处理这个过程(脚本中的其他地方)。到目前为止,这是我得到的最接近的:

require "pty"
catch :ready do
  begin
    PTY.spawn( "bin/start" ) do |stdin, stdout, pid|
      begin
        stdin.each { |line|
          throw(:ready) if line['worker ready']
        }
      rescue Errno::EIO
        puts "no more output"
      end
    end
  rescue PTY::ChildExited
    puts "child process exit"
  end
end # === end of catch block

# Continue with the rest of the script...

到目前为止它可以工作,但我对 Ruby 和流程不熟悉。我在网上看到的所有其他解决方案都需要管道、叉子和Process.detach. throw当我在 a 时使用,我做错了PTY.spawn什么吗?

4

0 回答 0