2 # = open3.rb: Popen, but with stderr, too
4 # Author:: Yukihiro Matsumoto
5 # Documentation:: Konrad Meyer
7 # Open3 gives you access to stdin, stdout, and stderr when running other
12 # Open3 grants you access to stdin, stdout, and stderr when running another
18 # stdin, stdout, stderr = popen3('nroff -man')
20 # Open3.popen3 can also take a block which will receive stdin, stdout and
21 # stderr as parameters. This ensures stdin, stdout and stderr are closed
22 # once the block exits. Example:
26 # Open3.popen3('nroff -man') { |stdin, stdout, stderr| ... }
31 # Open stdin, stdout, and stderr streams and start external executable.
36 # [stdin, stdout, stderr] = Open3.popen3(cmd)
42 # Open3.popen3(cmd) { |stdin, stdout, stderr| ... }
44 # The parameter +cmd+ is passed directly to Kernel#exec.
47 pw = IO::pipe # pipe[0] for read, pipe[1] for write
76 pi = [pw[1], pr[0], pe[0]]
82 pi.each{|p| p.close unless p.closed?}
87 module_function :popen3
91 a = Open3.popen3("nroff -man")
98 while line = a[1].gets