Created
June 8, 2016 11:08
-
-
Save Fonsan/a6b2168755476ee840bb568d970833e2 to your computer and use it in GitHub Desktop.
This file contains 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
require 'open3' | |
module Enumerable | |
alias :all_are? :all? | |
end | |
Open3.popen3(%(ruby -e 'STDOUT.sync = true; STDERR.sync = true;3.times { |i| STDOUT.puts(i); STDERR.puts(i); sleep 1 }')) do |stdin, stdout, stderr, wait_thr| | |
maxlen = 1024 | |
pipes = { | |
stdout => :stdout, | |
stderr => :stderr | |
} | |
until pipes.empty? | |
IO.select(pipes.keys).first.each do |io| | |
begin | |
puts "#{pipes[io]}: #{io.read_nonblock(maxlen)}" | |
rescue EOFError | |
pipes.delete(io) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment