Practical mod_perl / HTML Book /



previous page: 6.4.3. Global Variable Persistence
  
page up: HTML Version of the book
  
next page: 6.4.5. Redirecting STDOUT into a Scalar Variable

6.4.4. STDIN, STDOUT, and STDERR Streams


Under mod_perl, both STDIN and STDOUT are tied to the socket from which the request originated. If, for example, you use a third-party module that prints some output to STDOUT when it shouldn't (for example, control messages) and you want to avoid this, you must temporarily redirect STDOUT to /dev/null. You will then have to restore STDOUT to the original handle when you want to send a response to the client. The following code demonstrates a possible implementation of this workaround:

{
    my $nullfh = Apache::gensym( );
    open $nullfh, '>/dev/null' or die "Can't open /dev/null: $!";
    local *STDOUT = $nullfh;
    call_something_thats_way_too_verbose( );
    close $nullfh;
}

The code defines a block in which the STDOUT stream is localized to print to /dev/null. When control passes out of this block, STDOUT gets restored to the previous value.

STDERR is tied to a file defined by the ErrorLog directive. When native syslog support is enabled, the STDERRstream will be redirected to /dev/null.

 

Continue to:

  • prev: 6.4.3. Global Variable Persistence
  • Table of Contents
  • next: 6.4.5. Redirecting STDOUT into a Scalar Variable







TOP
previous page: 6.4.3. Global Variable Persistence
  
page up: HTML Version of the book
  
next page: 6.4.5. Redirecting STDOUT into a Scalar Variable


Menu

  • HTML Book
  • PDF Book
  • Download Code
  • Table of Contents
  • Errata
  • mod_perl2 User's Guide
  • Sitemap

Search


Add to Google




Creative Commons License


Written by
Eric Cholet (Logilune) and
Stas Bekman (StasoSphere & Free Books).


[ Privacy Policy | Terms of Use | About Us | Search ]

© 2007 StasoSphere.com