Dave Burt
4/17/2006 10:03:00 PM
rj-cole wrote:
> I'm trying to write a function that will spawn a process, and after a
> timeout kill the process if it hasn't terminated yet.
>
> def spawn(inputString, cmd, outputFileName)
> inp = IO.popen("(" + cmd + ") > #{outputFileName} ", "w")
> inp << inputString
> inp.close_write
> end
>
> What is the best way to change this so that (i) it works, and (ii) it
> gives the process some number of seconds to complete, and if it hasn't
> completed then it kills it and returns an error?
Use Timeout from the Standard Library.
require 'timeout'
Timeout.timeout(60) do
spawn foo, bar, baz
end
Cheers,
Dave
Cheers,
Dave