Getting rid of ruby stdin/stdout buffering -



Getting rid of ruby stdin/stdout buffering -

i'm trying write ruby script filter output of tailed file (tail -f log.log | ./my_filter.rb). believe i've set stdin , stdout read synchronously, still see output coming out in delayed batches, 20 or lines @ time, rather in realtime.

i can reproduce problem code simple as:

#!/usr/bin/ruby $stdout.sync = true $stdin.sync = true argf.each |line| puts line end

am missing setting eliminate buffering, or along lines?

edit: clarify, if tail -f log see many lines written per second.

if you're dealing files, want io#fsync, says:

immediately writes buffered info in ios disk. note fsync differs using io#sync=. latter ensures info flushed ruby’s buffers, not guarantee underlying operating scheme writes disk.

if you're dealing standard input , output, might seek requiring io/console see if using io::console#ioflush gives behavior need. documentation says:

flushes input , output buffers in kernel. must require ‘io/console’ utilize method.

as example, consider:

require 'io/console' argf.each |line| $stdout.puts line $stdout.ioflush end

ruby stdout stdin

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -