Forum Moderators: coopster & phranque

Message Too Old, No Replies

Need help debugging a script

Trying to redirect my STDOUT to a variable... and then back again.

         

maximillianos

6:52 pm on Feb 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello everyone.

I'm stuck on a coding issue and was hoping someone in this forum might have some insight.

I'm trying to redirect my cgi script (perl) output to a variable, store it all in the database, and then switch the output back to normal and output the page to the web browser.

I am able to switch the output to my variable and store it in my database, but I cannot for the life of me figure out how to switch the output back to normal so I can write back to the user's web browser?

Here is my code:

# First I close STDOUT, then re-assign it to my variable $dbout...

$dbout = STDOUT;
close STDOUT;
open STDOUT, '>&', \$dbout or die "Can't open STDOUT: $!";

# Now I have my cgi/perl script run and generate the webpage output... which now gets dumped into my variable $dbout

print "<HTML>";
print "...";
print "</HTML>";

# Once the page is saved in the DB... I have no idea how to switch it back so that my "print" statements go back to normal and not to the $dbout variable?!?

I've tried 100 variations of code I found in various man pages, etc. Nothing seems to work. Any ideas or suggestions would be GREATLY appreciated... ;-)

Thanks!

phranque

1:55 am on Feb 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



try this before:
open SAVEOUT, ">&STDOUT";

and then after:
close STDOUT;
open STDOUT, ">&SAVEOUT";

maximillianos

1:35 pm on Feb 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks! I see what you are suggesting. Save it first in a backup, then do my redirect, then reset it back.

It works!