On Tue, 28 Mar 2006, Andrew Johnson wrote: > On Mon, 27 Mar 2006 11:52:10 +0900, yahn <yahn15 / hotmail.com> wrote: >> How do you do something like gets but without blocking? All I want to >> do is try to see if anything was input and if it wasn't then just go on >> running the rest of my code. > > I was going to suggest using the Fcntl extension to set the non-blocking > bit on the filehandle as an alternative, but it appears to not be working > (at least on my linux box). That is to say, this script sits and waits for > input: > > require 'fcntl' > > flags = STDIN.fcntl(Fcntl::F_GETFL, 0) > flags |= Fcntl::O_NONBLOCK > STDIN.fcntl(Fcntl::F_SETFL, flags) > > a = STDIN.gets > puts "You got #{a}" > > > Whereas the equivalent Perl script: > > use Fcntl; > > $flags = fcntl(STDIN,F_GETFL,0); > $flags |= O_NONBLOCK; > fcntl(STDIN,F_SETFL,O_NONBLOCK); > > $foo = <STDIN>; > print "Got $foo\n"; > > doesn't block and finishes immediately. > > andrew this seems like a bug... maybe a post to ruby-core? -a -- share your knowledge. it's a way to achieve immortality. - h.h. the 14th dali lama