From: Brian Candler Date: 2003-05-28T01:48:12+09:00 Subject: Re: system calls On Tue, May 27, 2003 at 10:24:50PM +0900, mgarriss wrote: > so I can get the standard output from a system call: > > s = `date` > > and I can get the return value: > > system( "date" ) > > and I have no idea how to get the standard error: > > ??? > > but what I really want is all three, like: > > out, err, ret = really_cool_system( "date" ) This is almost what you want, except that the exit code is wrong and I don't know how to fix it: require 'open3' module Kernel private def really_cool_system(*args) inp, out, err = Open3.popen3(*args) ret1 = ret2 = nil t1 = Thread.new do inp.close end t2 = Thread.new do ret1 = out.read out.close end t3 = Thread.new do ret2 = err.read err.close end t1.join t2.join t3.join return ret1, ret2, $? end end irb(main):024:0> really_cool_system("ls","/dev/null","/dev/foo") => ["/dev/null\n", "ls: /dev/foo: No such file or directory\n", 65280] Regards, Brian.