From: Rudolf Polzer Date: 2003-09-19T20:17:26+09:00 Subject: Re: closing stderr Scripsit illa aut ille �Robert Klemme� : > "Rudolf Polzer" schrieb im Newsbeitrag > news:slrnbmjng5.kqp.denshimeiru-sapmctacher@message-id.durchnull.ath.cx... > > Scripsit illa aut ille �Robert Klemme� : > > > "Michael Garriss" 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. Then use the StringIO trick from the other posting. I thought about an external library which is an interface to an existing C library which writes to stderr (file descriptor 2). -- The only thing that Babelfish is good at is proving that Vogons are great poets. Josef 'Jupp' Schugt in japan.anime.evangelion