def runcommand
opts = {"env" => @environment,
"stdout" => @stdout,
"stderr" => @stderr,
"cwd" => @cwd}
opts["stdin"] = @stdin if @stdin
thread = Thread.current
@status = systemu(@command, opts) do |cid|
begin
if timeout.is_a?(Fixnum)
sleep timeout
else
while(thread.alive?)
sleep 0.1
end
end
if (Process.kill(0, cid))
if timeout
if Util.windows?
Process.kill('KILL', cid)
else
Process.kill('TERM', cid)
sleep 2
Process.kill('KILL', cid) if (Process.kill(0, cid))
end
end
Process.waitpid(cid) unless thread.alive?
end
rescue SystemExit
rescue Errno::ESRCH
rescue Errno::ECHILD
Log.warn("Could not reap process '#{cid}'.")
rescue Exception => e
Log.info("Unexpected exception received while waiting for child process: #{e.class}: #{e}")
end
end
@status.thread.kill
@status
end