title: How to wait for process to finish using IO.popen?
body: <p>I'm using <code>IO.popen</code> in Ruby to run a series of command line commands in a loop. I then need to run another command outside of the loop. The command outside of the loop cannot run until all of the commands in the loop have terminated. </p>
  
  <p>How do I make the program wait for this to happen? At the moment the final command is running too soon.</p>
  
  <p>An example:</p>
  
  <pre><code>for foo in bar
      IO.popen(cmd_foo)
  end
  IO.popen(another_cmd)
  </code></pre>
  
  <p>So all <code>cmd_foos</code> need to return before <code>another_cmd</code> is run.</p>