From: Raveendran .P on 14 Jul 2010 02:22 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 -- Posted via http://www.ruby-forum.com/.
From: F. Senault on 14 Jul 2010 03:59 Le 14 juillet � 08:22, Raveendran .P a �crit : > Need: > > a=gets() is waiting for input. I need to wait only 20 seconds. Look at the Timeout standard library : begin Timeout.timeout(20) do a = gets() end rescue Timeout::Error puts "Timeout. 20 seconds gone, etc" end Fred -- What would be the point of cyphering messages that very clever enemies couldn't break? You'd end up not knowing what they thought you thought they were thinking... (Terry Pratchett, in The Fifth Elephant)
From: Brian Candler on 14 Jul 2010 04:04 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/.
From: Raveendran .P on 14 Jul 2010 04:21 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/.
From: Heesob Park on 14 Jul 2010 04:45 Hi, 2010/7/14 Raveendran .P <jazzezravi(a)gmail.com>: > > 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 > If you try the code with Ruby 1.9.1 (http://rubyforge.org/frs/download.php/71495/rubyinstaller-1.9.1-p429.exe), It will work. Regards, Park Heesob
|
Next
|
Last
Pages: 1 2 Prev: [ANN] Ruby|Web Conference Next: I have some questions about this modified String class |