Skip to content

Instantly share code, notes, and snippets.

@Fonsan
Created June 8, 2016 11:08
Show Gist options
  • Save Fonsan/a6b2168755476ee840bb568d970833e2 to your computer and use it in GitHub Desktop.
Save Fonsan/a6b2168755476ee840bb568d970833e2 to your computer and use it in GitHub Desktop.
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