Open3.popen3 starts an external program and returns separate handles for its standard input, standard output, and standard error. Require the open3 library first; unlike the Ruby session's own streams, these handles communicate directly with the child process. section 14.6.2
A cat session
require 'open3'\nstdin, stdout, stderr = Open3.popen3("cat")\nstdin.puts("Hi.\\nBye")\nstdout.gets # => "Hi.\\n"\nstdout.gets # => "Bye\\n"
The returned values support a deliberately separated communication model:
- Write data to the input handle and read the child process's output through the output handle. section 14.6.2
- Capture errors independently through the error handle, while a fourth return value provides a Process::Waiter object that can be ignored in simple cases. section 14.6.2
