Thanks Paul,

The interesting thing is, I have tried this trick with Turbo C++ under 
windows 2000. when I wrote a simple program calling int21/46, or the C dup2 
function, and used "redir net use...", it worked. But when I copied that 
piece of asm or dup2 code into the C program that use system("net use..."), 
it does not work! So strange... It may not be a problem of ruby, so...


Shannon



>From: "Paul Melis" <paul / floorball.nl>
>Reply-To: ruby-talk / ruby-lang.org
>To: ruby-talk / ruby-lang.org (ruby-talk ML)
>Subject: Re: catch stderr
>Date: Sun, 1 Dec 2002 00:58:55 +0900
>
>"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


_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*  
http://join.msn.com/?page=features/junkmail