Ruby 从长时间运行的进程中捕获并显示标准输出文本
我正在使用Ruby脚本启动一个长时间运行的进程,该进程定期将信息发送到STDOUT。例如:Ruby 从长时间运行的进程中捕获并显示标准输出文本,ruby,stdout,Ruby,Stdout,我正在使用Ruby脚本启动一个长时间运行的进程,该进程定期将信息发送到STDOUT。例如: Open3.popen3("tail -f ./test_file") do |stdin, stdout, stderr| # continually read text that the tail command sends to it's STDOUT and # send that text to *this* process's STDOUT # # Tried the fol
Open3.popen3("tail -f ./test_file") do |stdin, stdout, stderr|
# continually read text that the tail command sends to it's STDOUT and
# send that text to *this* process's STDOUT
#
# Tried the following but it doesn't work
#
while !stdout.eof?
puts stdout.read
end
end
#!/usr/bin/env ruby
io_obj = IO.popen('tail -f ./test_file')
while !io_obj.eof?
# read a line of text at a time
result = io_obj.readline
puts result
end