I'm in the process of fixing up a large cgi application so that it runs correctly under mod_perl 2.0, using Apache::Registry. There were a handful of END blocks, most of which I've rewritten using the cleanup_register function, which works great. Now I've come to one which prints to STDOUT in an END block, but it's not printing anything since I switched to cleanup_register. It seems like Apache is closing STDOUT (or untying it, or whatever) before it runs the cleanup code.
Anyone know of a different way I could print to STDOUT as the script is finishing, or get STDOUT working in the cleanup code?
The script below is a simple example of what I'm talking about. "finishing stdout." never gets printed. The commented out lines didn't help.
#!/usr/local/bin/perl
print "Content-type: text/plain\n\n(in main code)\n";
# my $old;
# open ($old, ">&STDOUT") or die "Can't dup STDOUT: $!";
my $r = Apache->request;
$r->pool->cleanup_register(\&finish);
sub finish
{
print STDERR "finishing...\n";
# open (STDOUT, ">&", $old) or die "Can't dup \$old: $!";
print "finishing stdout.\n";
print STDERR "finished.\n";
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.