From: kero@...38c.nl (Kero van Gelder) Date: 2002-02-20T04:08:27+09:00 Subject: Re: weird output >alog = "access_log" >$stdout.sync=true >lines = 0 >lasttime = 0 >IO.popen("tail -f #{alog}").each do |line| > lines += 1 > t = Time.now.to_i > if t >= lasttime + +5 > d = `date` > d.chop! > puts "#{d}\t#{t - lasttime}\t#{lines}\t#{lines/5}" > lasttime = t > lines = 0 > end >end > >and it works fine for 99% of the time, but every once in a while I'll >get output that looks like this: > >Tue Feb 12 10:43:34 PST 2002 5 155 31 >Tue FebTue Feb 12 10:44:13 PST 2002 5 200 40 >Tue Feb 12 10:44:18 PST 2002 5 220 44 > >Or: >Tue Feb 12 10:44:38 PST 2002 5 150 30 >Tue Feb 1209 PST 2002 5 206 41 >Tue Feb 12 10:44:14 PST 2002 5 204 40 Some native processes interfere with each other. they fight for the same tty, which you gave to them with IO.popen. Ruby uses an internal system for threads, which does not really like native threads/processes. What it is exactly that goes wrong, I do not know. It almost seems IO.popen can be ran twice when more than 1 line of output becomes available. I guess it is the combination with "tail -f", which is not such a regular, behaving program as it may seem. You may want to find out what "tail -f" does precisely. You could then emulate that behaviour from Ruby, perhaps. Good luck, Kero. +--- Kero ------------------------------ kero@chello.nl ---+ | Don't split your mentality without thinking twice | | Proud like a God -- Guano Apes | +--- M38c ------- http://members.chello.nl/~k.vangelder ---+