# = open3.rb: Popen, but with stderr, too
# Author:: Yukihiro Matsumoto
# Documentation:: Konrad Meyer
# Open3 gives you access to stdin, stdout, and stderr when running other
# Open3 grants you access to stdin, stdout, and stderr when running another
# stdin, stdout, stderr = popen3('nroff -man')
# Open3.popen3 can also take a block which will receive stdin, stdout and
# stderr as parameters. This ensures stdin, stdout and stderr are closed
# once the block exits. Example:
# Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... }
# Open stdin, stdout, and stderr streams and start external executable.
# stdin, stdout, stderr = Open3.popen3(cmd)
# Open3.popen3(cmd) { |stdin, stdout, stderr| ... }
# The parameter +cmd+ is passed directly to Kernel#exec.
# _popen3_ is like _system_ in that you can pass extra parameters, and the
# strings won't be mangled by shell expansion.
# stdin, stdout, stderr = Open3.popen3('identify', '/weird path/with spaces/and "strange" characters.jpg')
pw = IO::pipe # pipe[0] for read, pipe[1] for write
pi = [pw[1], pr[0], pe[0]]
pi.each{|p| p.close unless p.closed?}
a = Open3.popen3("nroff -man")