How timeout $stdin.gets?

timeout(1) do
  $stdin.gets
end

This program is not stopped until user input enter key.
Help me!!

···

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

Which version of ruby did you use? It works for me.

ruby-1.9.2-p180 :003 > Timeout.timeout(1) do
ruby-1.9.2-p180 :004 > line = gets
ruby-1.9.2-p180 :005?> end
Timeout::Error: execution expired
        from (irb):4:in `gets'
        from (irb):4:in `gets'
        from (irb):4:in `block in irb_binding'
        from (irb):3
        from /home/jduan/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'

-Jingjing

···

-----Original Message-----
From: Kyung won Cheon [mailto:chonkw@nate.com]
Sent: Wednesday, November 09, 2011 10:15 PM
To: ruby-talk ML
Subject: How timeout $stdin.gets ?

timeout(1) do
  $stdin.gets
end

This program is not stopped until user input enter key.
Help me!!

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

windows7
ruby 1.8.6

···

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

For your particular use case can you simply refactor it to use select?

ruby-1.8.6-p420 :001 > readable = select([$stdin], , , 1)
  => nil

Sam

···

On 10/11/11 20:40, Kyung won Cheon wrote:

windows7
ruby 1.8.6

-----Messaggio originale-----

···

Da: Sam Duncan [mailto:sduncan@wetafx.co.nz]
Inviato: giovedì 10 novembre 2011 20:11
A: ruby-talk ML
Oggetto: Re: How timeout $stdin.gets ?

On 10/11/11 20:40, Kyung won Cheon wrote:

windows7
ruby 1.8.6

For your particular use case can you simply refactor it to use select?

ruby-1.8.6-p420 :001 > readable = select([$stdin], , , 1)
  => nil

Sam

--
Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco + solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a persona
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid979&d)-12