Last active
October 27, 2017 13:34
-
-
Save mvlootman/00cf1d012190b7d7b13c9b7d69314b7b to your computer and use it in GitHub Desktop.
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
reader, writer = IO.pipe # writes in parent -> reads in child | |
reader2, writer2 = IO.pipe # writes in child -> reads in parent | |
Process.run(command: "./child", input: reader, output: writer2) do | |
puts "inside master block" | |
writer.puts "message from master 2" | |
end | |
reader2.each_line { |x| puts "rcvd: #{x}"} | |
puts "done" # doesn't get to this line | |
# Outputs: | |
# inside master block | |
# rcvd: incoming:message from master 2 | |
# rcvd: writing to standard output from child | |
# rcvd: child finished | |
#Child code: | |
puts "child process" | |
incoming = STDIN.gets | |
puts "incoming:#{incoming}" | |
STDOUT << "writing to standard output from child" | |
puts "\nchild finished" | |
STDOUT.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment