Ahmad Azizan wrote: > Ahmad Azizan wrote: >> Hello, >> >> I'm trying to get an output from /var/log/syslog for certain amount of >> time by executing %x[sudo tail -f /var/log/syslog] >> >> Is it possible to set a timer for the execution, and if the time end, >> the execution will end (like we do Ctrl+C) ? >> >> Thank you > > I think I've got the solution, > > #!/usr/bin/ruby > > require 'timeout' > begin > status = Timeout::timeout(10) do > %x[sudo tail -f /var/log/messages] > end > rescue Timeout::Error > puts 'execution expired' > end > > This might do the job > I don't think you will get a value in status that way. Try this: require 'timeout' output = [] begin Timeout.timeout 5 do IO.popen("ping 192.168.1.1") do |pipe| while line = pipe.gets output << line end end end rescue TimeoutError end puts output -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407