# File lib/posix/spawn.rb, line 293 def popen4(*argv) # create some pipes (see pipe(2) manual -- the ruby docs suck) ird, iwr = IO.pipe ord, owr = IO.pipe erd, ewr = IO.pipe # spawn the child process with either end of pipes hooked together opts = ((argv.pop if argv[-1].is_a?(Hash)) || {}).merge( # redirect fds # close other sides :in => ird, iwr => :close, :out => owr, ord => :close, :err => ewr, erd => :close ) pid = spawn(*(argv + [opts])) [pid, iwr, ord, erd] ensure # we're in the parent, close child-side fds [ird, owr, ewr].each { |fd| fd.close } end