How to timeout subprocess in Ruby -
i want test process working run:
cmd = "my unix command" results = `#{cmd}` how can add timeout command if takes more x seconds can assume not working?
ruby ships witrh timeout module.
require 'timeout' res = "" status = timeout::timeout(5) {res = `#{cmd}`} rescue timeout::error # bit of experimenting: res = nil status = timeout::timeout(1) {res = `sleep 2`} rescue timeout::error p res # nil p status # timeout::error res = nil status = timeout::timeout(3) {res = `sleep 2`} rescue timeout::error p res # "" p status # ""
Comments
Post a Comment