Last active
December 17, 2015 04:19
-
-
Save kesor/5549876 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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