Skip to content

Instantly share code, notes, and snippets.

@mvlootman
Last active October 27, 2017 13:34
Show Gist options
  • Save mvlootman/00cf1d012190b7d7b13c9b7d69314b7b to your computer and use it in GitHub Desktop.
Save mvlootman/00cf1d012190b7d7b13c9b7d69314b7b to your computer and use it in GitHub Desktop.
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