Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Redirecting STDIN / Logging CGI App

by crenz (Priest)
on Dec 21, 2004 at 21:29 UTC ( #416624=perlquestion: print w/ replies, xml ) Need Help??
crenz has asked for the wisdom of the Perl Monks concerning the following question:

Fellow monks,

I need to debug a badly written "everything-in-one-script" kind of CGI application. For that, I need to log all the input and output. I already managed to log the output by inserting something like this at the top of the application:

BEGIN { my $tee = new IO::Tee(\*STDOUT, ">logfile"); select($tee); }

I'd like to do something similar with STDIN. IO::Tee can also handle reading, but I don't know how to "replace" the current STDIN with $tee_in. I am probably looking for something like *STDIN = $tee (which of course won't work).

Comment on Redirecting STDIN / Logging CGI App
Select or Download Code
Replies are listed 'Best First'.
Re: Redirecting STDIN / Logging CGI App
by dragonchild (Archbishop) on Dec 22, 2004 at 12:55 UTC
    If this is a script that is executed whenever a request comes in (i.e., no mod_perl or other persistent framework), you could do something like:
    1. Slurp STDIN into a scalar in a BEGIN block.
    2. Log the scalar.
    3. Use IO::Scalar to treat the scalar like a filehandle.
    4. Reassign STDIN to the scalar-filehandle.

    As for reassigning, you may be looking for something like open( STDIN, '<<', $scalar ); I'm grabbing this from p.442 of the Camel 3rd edition section on Interprocess Communication.

    Being right, does not endow the right to be rude; politeness costs nothing.
    Being unknowing, is not the same as being stupid.
    Expressing a contrary opinion, whether to the individual or the group, is more often a sign of deeper thought than of cantankerous belligerence.
    Do not mistake your goals as the only goals; your opinion as the only opinion; your confidence as correctness. Saying you know better is not the same as explaining you know better.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://416624]
Approved by ChrisR
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (10)
As of 2015-07-30 23:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (273 votes), past polls