Catch stderr

Hi,

I have some question about catching stderr output in ruby… Please read
the following simple code.

STDERR.reopen STDOUT
result=net use abc
print “res=”, result

while abc is not available on my LAN. I didn’t succeed in catch the
stderr output to my program.

I searched the talk archive, found some discussion, but I still have
doubts. I refered to post #47612 and #47578, and copied the first line
of code above. It does not work. Moreover, in sample code from #47578, I
found some key words I don’t recognize, such as “ensure… end” and
"redirect… end". I tried to search these in the html help of ruby
(came with the windows install package), but can’t find any info. I also
need some suggestion on how to find info in the help file. Last time I
tried to find reserved word “in”, in the help file, also failed… :frowning:

Shannon

“Shannon Fang” xrfang@hotmail.com wrote in message
news:20021129220610.990B.XRFANG@hotmail.com

Hi,

I have some question about catching stderr output in ruby… Please read
the following simple code.

STDERR.reopen STDOUT
result=net use abc
print “res=”, result

while abc is not available on my LAN. I didn’t succeed in catch the
stderr output to my program.

Since you seem to be on windows, perhaps that is screwing up the redirect
stuff. Windows is not very good at the unix ways of I/O streams.

One way of capturing stderr (or actually redirecting) is using the “redir”
utility included in DJGPP (included in
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2/djdev203.zip).
It allows you to redirect stderr to stdout (or a file), so you can do

irb(main):001:0> res = redir -eo net use abc
“System error 67 has occurred.\n\nThe network name cannot be found.\n\n”
irb(main):002:0> res
“System error 67 has occurred.\n\nThe network name cannot be found.\n\n”

Good luck,
Paul