From: Ken Bloom Date: 2007-12-06T09:40:00+09:00 Subject: Re: How to redirect a "system" standard output and standard error to a variable (Linux) On Tue, 27 Nov 2007 16:17:30 -0500, Venks wrote: > Note: parts of this message were removed by the gateway to make it a > legal Usenet post. > > To clarify further I want to capture any standard output or standard > error. > > Thanks, > > ---------- Forwarded message ---------- From: Venks > Date: Nov 27, 2007 3:58 PM > Subject: How to redirect a "system" standard output to a variable To: > ruby-talk@ruby-lang.org > > > Hi, > > I need to redirect any standard output thrown when using a system call > into a Ruby variable. I tried to search for a solution but couldn't find > anything that worked. May be I am not using the right search terms. > > Here is what I am trying to do. > > begin > > `rm somefile` > > end > > If "somefile" doesn't exist the OS throws the message "rm: cannot remove > `somefile': No such file or directory" which I want to capture into a > variable. > > Thanks, You need to use popen3, because the message is printed on standard error, not standard out. --Ken -- Ken (Chanoch) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/