From: Chris Gehlker Date: 2002-02-22T05:52:23+09:00 Subject: Re: Now I'm really confused! On 2/20/02 12:37 PM, "Chris Gehlker" wrote: > I'm still struggling with producing RubyStudio. The following example > illustrates my dilemma: > > This works from the shell: > $stdout.print "Enter a string:" > a = $stdin.gets > > But hangs the thread in RubyStudio that's waiting to see some output from > Ruby. This however works in both environments: > > $stdout.print "Enter a string:" > $stdout.flush > a = $stdin.gets > > What I can't figure out is why Ruby behaves differently depending on how it > was launched. Does tcsh set some environmental variable that tells Ruby not > to buffer output? I printed out man tcsh but it's a small book without an > index. Please help. > > TIA > Chris Here I go answering my own question. I'm doing this for the sake of the archive. It turns out that there are two solutions, at least. The easy one is to prepend $stdout.sync= true To the program in the IDE's source window. The hard way is to use setvbuf() from C. I say that its the hard way because it would require me to drop out of the high level cocoa API and write a lot of RubyStudio in straight C. There may be another way using BSD file descriptors. I'm going to go look that up. -- There is, nevertheless, a certain respect and a general duty of humanity that ties us, not only to beasts that have life and sense, but even to trees and plants. -Michel de Montaigne, essayist (1533-1592)