Park Heesob wrote:
> 
> "Gilles Filippini" <gilles.filippini / free.fr> wrote in message
> news:3D298A0E.35ECAE66 / free.fr...
> > Hi,
> >
> > I saw many examples about how to redirect standard output to - say - a
> > string buffer.
> > What about standard error? Has anybody already done this?
> >
> > _gilles.
> 
> Hi,
> 
> You can redirect standard error to file like this:
> 
> def redir(redout, rederr)
>         raise unless block_given?
>         oldout, olddef, olderr = $stdout.dup, $defout.dup, $stderr.dup
>         begin
>                 f1 = File.open(redout,'w+')
>                 f2 = File.open(rederr,'w+')
>                 $stdout = f1.dup
>                 $defout = f1.dup
>                 $stderr = f2.dup
>                 yield
>         ensure
>                 f1.close
>                 f2.close
>                 $stdout = oldout
>                 $defout = olddef
>                 $stderr = olderr
>         end
> end
> 
> redir("/tmp/stdout", "/tmp/stderr") do
>   puts "hello, world!"
>   `ls notexist`
> end
> 
> Park Heesob

So, to redirect them to something else than a file I have then to use
redir with a pipe entry and to use a thread to transfert the pipe output
to what I want.
I've tried this and it does work.
Thanks a lot!
But I'm curious about why Massimiliano's method doesn't work for
$stderr...

_gilles.