From: "J.Hawkesworth" Date: 2003-05-28T01:56:41+09:00 Subject: Re: system calls Don't know if this helps but I recall that in perl you have to divide by 256 to get the real return value. (Tried to test here but running under Windows and therefore have no 'fork' to eat really_cool_system with). All the best, Jon -----Original Message----- From: Brian Candler [mailto:B.Candler@pobox.com] Sent: 27 May 2003 17:48 To: ruby-talk ML 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. ________________________________________________________________________ This e-mail has been scanned for all viruses by Star Internet. The service is powered by MessageLabs. For more information on a proactive anti-virus service working around the clock, around the globe, visit: http://www.star.net.uk ________________________________________________________________________ _____________________________________________________________________ This message has been checked for all known viruses by Star Internet delivered through the MessageLabs Virus Control Centre. For further information visit http://www.star.net.uk/stats.asp _____________________________________________________________________ Any views or personal opinions expressed within this email may not be those of Talis Information Ltd. The content of this email message and any files that may be attached are confidential, and for the usage of the intended recipient only. If you are not the intended recipient, then please return this message to the sender and delete it. Any use of this e-mail by an unauthorised recipient is prohibited.