def run_command
@child_pid = fork_subprocess
configure_parent_process_file_descriptors
GC.disable
propagate_pre_exec_failure
@result = nil
@execution_time = 0
write_to_child_stdin
until @status
ready = IO.select(open_pipes, nil, nil, READ_WAIT_TIME)
unless ready
@execution_time += READ_WAIT_TIME
if @execution_time >= timeout && !@result
raise CommandTimeout, "command timed out:\n#{format_for_exception}"
end
end
if ready && ready.first.include?(child_stdout)
read_stdout_to_buffer
end
if ready && ready.first.include?(child_stderr)
read_stderr_to_buffer
end
unless @status
if results = Process.waitpid2(@child_pid, Process::WNOHANG)
@status = results.last
redo
end
end
end
self
rescue Exception
Process.waitpid2(@child_pid, Process::WNOHANG) rescue nil
raise
ensure
GC.enable
close_all_pipes
end