From: kwatch@... (kwatch) Date: 2002-05-09T22:20:17+09:00 Subject: Re: gets and eof? I tried. The following is the result: .============================ prog1.rb == loop do break if $stdin.eof? line = $stdin.gets puts "<-- #{line}" end .======================================== .============================ prog2.rb == loop do line = $stdin.gets break if $stdin.eof? puts "<-- #{line}" end .======================================== .---------------------------------------- % ruby prog1.rb hoge <-- hoge # OK geji <-- geji # OK ^D % % ruby prog2.rb hoge geji <-- hoge # why? bake <-- geji # why? ^D % .---------------------------------------- It's mystery... Regards, kwatch Paul Brannan wrote in message news:<20020508144224.U21767@atdesk.com>... > I have a program that reads input from a socket and displays output on > the terminal. It exits on end of file. The loop looks something like: > > loop do > break if $stdin.eof? > line = $stdin.gets > puts "<-- #{line}" > end > > However, when I first wrote it, I instead wrote: > > loop do > line = $stdin.gets > break if $stdin.eof? > puts "<-- #{line}" > end > > The first case works correctly. The second case does not; when I type a > line, it doesn't show up until the second line is typed. This happens > whether I am using $stdin or whether I am using a socket (returned by > TCPServer#accept). Why does this happen in the second case? > > Paul