title: Fork child process with timeout and capture output
body: <p>Say I have a function like below, how do I capture the output of the Process.spawn call? I should also be able to kill the process if it takes longer than a specified timeout.</p>
  
  <p>Note that the function must also be cross-platform (Windows/Linux).</p>
  
  <pre><code>def execute_with_timeout!(command)
    begin
      pid = Process.spawn(command)     # How do I capture output of this process?
      status = Timeout::timeout(5) {
        Process.wait(pid)
      }
    rescue Timeout::Error
      Process.kill('KILL', pid)
    end
  end
  </code></pre>
  
  <p>Thanks.</p>