我想启动一个 java servlet,观察它的标准输出,直到我看到它已完全加载,然后在保持该进程运行的同时返回我的 rake 任务的其余部分。目前我有这样的事情:
IO.popen "java -jar ./tools/tests/servlet.jar" do |io|
io.each do |line|
puts line
Process.detach(io.pid) if line.include? 'Server ready.' # need help here
end
end
puts "Ready..."
如何退出此 IO 块以继续执行任务,同时保持进程运行?谢谢!
编辑:临时错误解决方案
def with_server_running
IO.popen "java -jar ./tools/tests/servlet.jar" do |io|
io.each do |line|
puts line
yield if line.include? 'Server ready.'
end
end
end
with_server_running do
puts "Ready..."
# rest of task
end