Created
September 3, 2015 15:59
-
-
Save Fryguy/2d2c996cc73ca9fd797b to your computer and use it in GitHub Desktop.
open4 threaded io handlers
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 'open4' | |
CASE = 'ruby -e "STDERR.puts \'a\'*70000; STDOUT.puts \'Hi\'"' | |
puts CASE | |
puts "---" | |
status = Open4.open4(CASE) do |pid, stdin, stdout, stderr| | |
stdin.close | |
threads = [ | |
Thread.new { stdout.each_line { |l| puts "STDOUT: #{l}" } }, | |
Thread.new { stderr.each_line { |l| puts "STDERR: #{l}" } } | |
] | |
threads.each(&:join) | |
end | |
puts status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment