Last active
November 9, 2020 02:23
-
-
Save mziwisky/2fe40ba44d9996718a18a158f1b7200a to your computer and use it in GitHub Desktop.
proxying I/O from one script to another
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| require 'open3' | |
| puts 'party time' | |
| output = '' | |
| status = Open3.popen2e('./sub.rb') do |std_in, std_out_err, wait_thr| | |
| Thread.new do | |
| while out = std_out_err.read(4) | |
| print(out); STDOUT.flush | |
| output += out | |
| end | |
| std_out_err.close | |
| end | |
| Thread.new do | |
| while input = STDIN.read(4) | |
| std_in.write(input) | |
| end | |
| std_in.close | |
| end | |
| wait_thr.value.exitstatus | |
| end | |
| puts "Output: #{output}" | |
| puts "Status: #{status}" |
This file contains hidden or 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
| #!/usr/bin/env ruby | |
| puts "it's a test!" | |
| loop do | |
| print "gimme something (q to quit)> " | |
| x = gets.chomp | |
| puts "you gave me #{x}" | |
| exit if x == 'q' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment