From: Victor Reyes Date: 2007-12-28T00:57:17+09:00 Subject: Re: Capturing error msgs from output = `cmd` ------=_Part_10787_2278065.1198771042914 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, Stefano, Well I have partial success at last! The expression *res =3D `ls abc 2>&1`* works fine on the irb. But not outsi= de of it. For the *Open3* method I tried your suggestion using the *stderr.read* and it works fine. I just needed a way to return the outcome of the request to the client caller. Since *Open3* works I will stay with it. Thanks to you, Tim Hunter, James Edward Gray II and Tom Metge for all your help. It is really appreciated. One day, when I become good at using Ruby, I might be able to help others. Victor On Dec 27, 2007 9:53 AM, Stefano Crocco wrote: > Alle gioved=EC 27 dicembre 2007, Victor Reyes ha scritto: > > Team, > > > > First, thank you for all your suggestions. They are greatly appreciated= . > > > > I tried the: > > *userCMD_output* *=3D `#{input} 2>&1`* > > But could not capture the error. Matter of facts the error to the *ls > > *command was displayed on the screen as: > > *ls: 0653-341 The file totot does not exist. * > > Are you trying it in IRB? in this case, maybe what you see is the return > value. Try puts userCMD_output and see whether it contains the error > message > or not. I tried this and it works: > > irb(main):001:0> res =3D `ls abc 2>&1` > =3D> "ls: impossibile accedere a abc: No such file or directory\n" > irb(main):002:0> res > =3D> "ls: impossibile accedere a abc: No such file or directory\n" > > > Second, I tried using the *Open3* method and when I tried to display th= e > > content of stdin, stdout and stderr just to inspect their contents, thi= s > is > > what's there: > > > > *stdin, stdout, stderr =3D Open3.popen3(input)* > > > > puts stdin > > puts stdout > > puts stderr > > > > *# > > # > > # * > > I don't understand how this works very well (I just started experimenting > with > Open3 yesterday), but I think you need to call their read methods, just a= s > you'd do with a file: > > puts stdout.read > =3D> ... > > This won't work with stdin (if I remember correctly) because it's not ope= n > for > writing. > > I hope this helps > > Stefano > > ------=_Part_10787_2278065.1198771042914--