From: Eric Hodel Date: 2007-01-28T10:39:56+09:00 Subject: Re: Net::HTTP Closes STDIN On Jan 27, 2007, at 17:13, James Edward Gray II wrote: > Kenneth Kalmer has brought up a HighLine issue and I'm trying to > look into it. Oddly, it seems to happen when interacting with the > Net::HTTP library. I've narrowed it done to the following example > on my box: > > $ cat stdin_closed_issue.rb > require 'net/http' > require 'io/wait' > > Net::HTTP.start('www.ruby-lang.org', 80) do |http| > body = http.get('/en/license.txt').body > end > p $stdin.eof? > $ ruby stdin_closed_issue.rb > true > > Can anyone explain why $stdin is closed after the page read? $stdin isn't closed, its at the end of file. Use #closed? to test if an IO has been closed or not. $ cat test.rb require 'net/http' require 'io/wait' Net::HTTP.start('www.ruby-lang.org', 80) do |http| body = http.get('/en/license.txt').body end p $stdin.closed? p $stdin.eof? $ ruby test.rb false # hit ^D to close $stdin on the sending side. true $ $ echo hi | ruby test.rb false false -- Eric Hodel - drbrain@segment7.net - http://blog.segment7.net I LIT YOUR GEM ON FIRE!