On Jan 27, 2007, at 18:38, James Edward Gray II wrote: > On Jan 27, 2007, at 7:39 PM, Eric Hodel wrote: > >> $stdin isn't closed, its at the end of file. Use #closed? to test >> if an IO has been closed or not. > > Right, good point. > > However, when I call eof?() before the Net::HTTP call it behaves > differently (stalls and prints false). Why does it not behave the > same after that page read? $ cat test.rb puts "closed? %p" % $stdin.closed? puts "eof? %p" % $stdin.eof? require 'net/http' require 'io/wait' Net::HTTP.start('localhost', 80) do |http| body = http.get('/').body end puts "closed? %p" % $stdin.closed? puts "eof? %p" % $stdin.eof? $ ruby test.rb closed? false type some text here eof? false closed? false eof? false $ For the first #eof? no data written, so Ruby waits until something's been flushed. I typed some text and hit return to flush the terminal's stdout (Ruby's $stdin). At the second #eof? no input on $stdin has been consumed, so Ruby doesn't need to check for #eof? again by waiting. $ cat test.rb puts "eof? %p" % $stdin.eof? gets puts "eof? %p" % $stdin.eof? $ ruby test.rb aoeu eof? false aoeu eof? false -- Eric Hodel - drbrain / segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!