"Rudolf Polzer" <denshimeiru-sapmctacher / durchnull.de> schrieb im
Newsbeitrag
news:slrnbmjng5.kqp.denshimeiru-sapmctacher / message-id.durchnull.ath.cx...
> Scripsit illa aut ille ?Robert Klemme? <bob.news / gmx.net>:
> > "Michael Garriss" <mgarriss / earthlink.net> schrieb im Newsbeitrag
news:3F69D414.70008 / earthlink.net...
> > > I would like to prevent some output that is going to stderr during a
> > > call to a third party lib just during that call.  My first guess
was:
> > >
> > > STDERR.close_write
> > > ThirdPartyLib::call_some_annoying_function
> > > STDERR.????
> > >
> > > I guess you can see my problem.  Can anyone give me a lead on this?
> [...]
> > $stderr = StringIO.new
> > STDERR = $stderr
>
> Are you sure it occupies file descriptor 2 (which external libraries
> normally use)?
>
>   def without_stderr(&block)
>     save = $stderr.dup()
>     $stderr.close() # this will affect STDERR, too.
>     begin
>       yield
>     ensure
>       $stderr = save.dup()
>       # SIDE EFFECT: the file descriptor STDERR points to will be valid
again
>     end
>   end
>
> However, this routine assumes that all file descriptors before
> $stderr are used. This is the case unless $stdin or $stdout have
> been closed. Is there something like dup2() in Ruby?

This routine has a totally different problem: closing $stderr make the lib
function abort because it will get an exception on writing to $stderr.
$stderr has to be something that is open.

Regards

    robert