title: Why does STDERR output from Ruby come before earlier STDOUT output when redirecting?
body: <p>In bash, this gives the output in the expected order:</p>
  
  <pre><code>ruby -e "puts 'one'; raise 'two'"
  one
  -e:1:in `&lt;main&gt;': two (RuntimeError)
  </code></pre>
  
  <p>But if I redirect STDERR to STDOUT, I get the error before the output, which I do not want:</p>
  
  <pre><code>ruby -e "puts 'one'; raise 'two'" 2&gt;&amp;1 | cat
  -e:1:in `&lt;main&gt;': two (RuntimeError)
  one
  </code></pre>
  
  <p>I want to redirect the output to a text file (it behaves the same way as <code>cat</code> above) and get both output and exceptions, but in the same order as when looking at the output in my terminal. Can this be achieved?</p>