Skip to content

Instantly share code, notes, and snippets.

@mxhold
Last active August 29, 2015 14:17
Show Gist options
  • Save mxhold/ba3549afd20db90ae2f1 to your computer and use it in GitHub Desktop.
Save mxhold/ba3549afd20db90ae2f1 to your computer and use it in GitHub Desktop.
require 'open3'
command = '$stderr.puts("X" * 70_000); $stdout.puts("X" * 70_000)'
full_command = "ruby -e '#{command}'"
Open3.popen3(full_command) do |_in, out, err, _t|
out.each { |line| $stdout.puts line }
err.each { |line| $stderr.puts line }
end
require 'open3'
command = '$stderr.puts("E" * 70_000); $stdout.puts("o" * 70_000)'
full_command = "ruby -e '#{command}'"
Open3.popen3(full_command) do |_in, out, err, _t|
threads = []
threads << Thread.new { out.each { |line| $stdout.puts line }}
threads << Thread.new { err.each { |line| $stderr.puts line }}
threads.each { |t| t.join }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment