From: "Mauricio Fernández" Date: 2003-02-16T03:04:13+09:00 Subject: Re: Capturing output from Kernel#system On Sun, Feb 16, 2003 at 02:55:01AM +0900, Tim Kynerd wrote: > Maybe I'm dumb, I dunno. > > I need to execute an external command and capture the output from it in a > Ruby structure. > > When I use the Kernel#system method to do this, I get the output just > fine, but I can't figure out how to capture it. The method returns true, > of course, but obviously true isn't what I want to capture! > > I'd like to avoid the obvious kludge of writing the command output to a > file and reading the file in Ruby. Isn't there a better way than that? The > pickaxe book isn't helping me here at all (maybe I didn't look where I > should have...). >> output = `uptime` => " 19:05:58 up 29 days, 9:51, 1 user, load average: 0.01, 0.04, 0.03\n" >> p output " 19:05:58 up 29 days, 9:51, 1 user, load average: 0.01, 0.04, 0.03\n" => nil -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com Computers are like air conditioners. Both stop working, if you open windows. -- Adam Heath