Reputation: 8158
I am using a Ruby script to launch a long-running process that periodically sends information to STDOUT. For example:
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
Upvotes: 0
Views: 206
Reputation: 8158
#!/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
Upvotes: 1