From: Stefano Crocco Date: 2007-12-27T23:53:45+09:00 Subject: Re: Capturing error msgs from output = `cmd` Alle giovedì 27 dicembre 2007, Victor Reyes ha scritto: > Team, > > First, thank you for all your suggestions. They are greatly appreciated. > > I tried the: > *userCMD_output* *= `#{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 = `ls abc 2>&1` => "ls: impossibile accedere a abc: No such file or directory\n" irb(main):002:0> res => "ls: impossibile accedere a abc: No such file or directory\n" > Second, I tried using the *Open3* method and when I tried to display the > content of stdin, stdout and stderr just to inspect their contents, this is > what's there: > > *stdin, stdout, stderr = 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 as you'd do with a file: puts stdout.read => ... This won't work with stdin (if I remember correctly) because it's not open for writing. I hope this helps Stefano