Skip to content

Instantly share code, notes, and snippets.

@Fryguy
Created September 3, 2015 15:59
Show Gist options
  • Save Fryguy/2d2c996cc73ca9fd797b to your computer and use it in GitHub Desktop.
Save Fryguy/2d2c996cc73ca9fd797b to your computer and use it in GitHub Desktop.
open4 threaded io handlers
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