I'm trying to write a ruby script to filter the output of a tailed file (tail -f log.log | ./my_filter.rb
). I believe I've set stdin and stdout to be read synchronously, but I still see my output coming out in delayed batches, 20 or so lines at a time, rather than in realtime.
I can reproduce the problem with code as simple as:
#!/usr/bin/ruby
$stdout.sync = true
$stdin.sync = true
ARGF.each do |line|
puts line
end
Am I missing a setting to eliminate buffering, or something along those lines?
Edit: To clarify, if I just tail -f
the log then I see many lines written per second.