Process wait with timeout in Ruby 1.8.x

This is working code for Ruby 1.9.x:

require ‘timeout’
pid = nil
begin
Timeout::timeout(2) {
pid = spawn(“pause”)
Process.wait(pid)
}
rescue Timeout::Error
begin
Process.kill(“KILL”,pid)
rescue
end
end

How can I do that in Ruby 1.8.x for Linux AND Windows?
Use case is to execute a system command and to kill it after a certain
time if the process does not terminate.

Thanks in advance!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs