From: Paul Brannan Date: 2002-07-30T22:35:03+09:00 Subject: Re: A very basic tail -f implementation On Tue, Jul 30, 2002 at 05:15:25AM +0900, Daniel Berger wrote: > # Ctrl-C to exit > while true > puts t.read > end I have an implementation of tail -f that looks similar, except it doesn't seek to the end of file at start, and it's called like this: File.open(filename) do |input| tail_f(input) do |line| puts line end end Two advantages here: 1) If an exception is raised from inside the block, the file will be properly closed. 2) I get my input line-by-line, which imo is much more useful than buffersize-by-buffersize. Some advantages of your implementation: 1) It is an object, and acts somewhat like an IO object, thus 2) If RCR#65 (http://www.rubygarden.org/article.php?sid=179) were accepted, it could easily be modified to inherit from IO and make this class act just like a pipe. 3) The sleep interval and buffer size are adjustable. My implementation: def clearerr(io) offset = io.tell io.seek(offset) end def tail_f(input) loop do line = input.gets yield line if not line.nil? if input.eof? then sleep 1 clearerr(input) end end end Paul