From: "Raveendran .P" Date: 2010-07-14T17:21:59+09:00 Subject: Re: gets() -- Need to skip when no response after 20seconds Hi Brain and Senault, The script is still waiting for input from User. ** But the same timeout code works for while loop printing up to 1000. I am using Windows XP Service pack 2, Ruby 1.8.7 Thanks Brian Candler wrote: > Raveendran .P wrote: >> Code: >> >> puts "Print your age" >> a=gets() >> puts "Timeout. 20 Seconds Gone. Please re-run the Applciation" >> >> >> Need: >> >> a=gets() is waiting for input. I need to wait only 20 seconds. If therre >> is no input for 20 seconds then script should continue the next line >> >> >> Thanks >> Raveendran P >> http://raveendran.wordpress.com > > require 'timeout' > a = nil > begin > puts "Print your age" > Timeout.timeout(20) do > a = gets > end > rescue Timeout::Error > puts "Timeout. 20 Seconds Gone. Please re-run the Applciation" > end > > # Warning: like most programs, this may not work as desired under > Windows -- Posted via http://www.ruby-forum.com/.