Skip to content

Instantly share code, notes, and snippets.

@kesor
Last active December 17, 2015 04:19
Show Gist options
  • Save kesor/5549876 to your computer and use it in GitHub Desktop.
Save kesor/5549876 to your computer and use it in GitHub Desktop.
Open3.popen3 cmd do |sin, sout, serr, wait_thr|
loop do
rs, _, _ = IO.select([sout,serr]) # no multi-assign in conditions
break if (sout.eof? and serr.eof?) or (sout.closed? and serr.closed?)
next if rs.empty?
rs.each do |readable_io|
log readable_io.gets # read a line from it
end
end
exit_status = wait_thr.value
raise "#{cmd} returned as failed" unless exit_status.success?
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment