Hi,

From: "Bill Atkins" <batkins57 / gmail.com>
>
> How can I determine if there's input waiting on STDIN before
> calling gets?

<laugh> I just posted this a minute ago on the 
Threading+TCPServer thread; if I'd seen your message
I'd have posted here instead... :)

I use:

if WINDOWS_VERSION
  require 'dl'
  $win32_console_kbhit = Win32API.new("msvcrt", "_kbhit", [], 'I')
  def console_input_ready?
    $win32_console_kbhit.call != 0
  end
else
  def console_input_ready?
    select([$stdin], nil, nil, 0) != nil
  end
end

Note that if you do a gets() when console_input_ready?
is true, you'll still block until the user hits <enter>.

BTW, I was using:

WINDOWS_VERSION = (RUBY_PLATFORM =~ /win32/) != nil


Regards,

Bill