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