Rudi Cilibrasi wrote:
> On 10/3/07, 7stud -- <dolgun / excite.com> wrote:
>> Stephen Ware wrote:
>> One thing I found puzzling is having to call STOUT.flush.  When I don't
>> include that statement, then the print statement is skipped.  Yet, if I
>> use puts instead of print, then the flush call isn't necessary.  Anyone
>> know why?
> 
> I guess it's because in Unix most text I/O at the text console is
> line-buffered by default.  See "cooked mode" e.g.
> http://meshier.com/docs/oreilly/unix2/upt/ch41_02.htm
> 
> for more info.  Roughly, the kernel is expected to collect input into 
> lines,
> and to allow stuff like backspace to work simply, it has to buffer a 
> whole line
> up and wait for return before sending it on to the application.  So that 
> is why
> your print doesn't print: it is not sending the return to cause the 
> flush.  But
> sending one yourself fixes it.  The puts has the \n so the flush
> happens automatically I guess.

Then why does this print command produce output without a call to flush:

print "Enter data: "
line = gets



-- 
Posted via http://www.ruby-forum.com/.