[CMI.PM] block STDERR from a CPAN module implemented in C?

Brandon Bowersox brandon at ojctech.com
Sat Nov 15 13:48:34 CST 2003


Since we've had such lively support lately...

How can I trap or block STDERR output from the XML::GDOME module 
which is an XS module that uses a C implementation?

Pretend Solution #1------------------------------------------
close STDERR;
XML::GDOME->foo; #call that generates STDERR

Pretend Solution #2------------------------------------------
local *STDERR;
open (STDERR, ">".File::Spec->devnull());
XML::GDOME->foo; #call that generates STDERR

#1 works but stops me from getting any of the helpful output from any 
part of my program below.  #2 does not work because the XML::GDOME 
calls are in a different scope where "local *STDERR" no longer 
applies.

Why do I want to do this?  XML::GDOME gives "critical" error messages 
on STDERR even when it works correctly and produces the right output.
The implementation seems to have trouble with reference counting and 
it hates when, for example, a document object is garbage collected 
when there are still node objects of that doc that have not been 
garbage collected.  XML::GDOME is no longer being actively improved, 
but I want to use it because it works and supports the DOM methods 
I need, including importNode().  And I want to capture the STDERR 
so all these messages do not fill up or overwhelm the Apache mod_perl 
CGI environment from which I'm calling XML::GDOME.

Brandon Bowersox



More information about the Champaign-Urbana mailing list