CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Beginner:
Adding header to STDERR, STDIN & STDOUT


New User

Sep 9, 2007, 2:30 PM

Post #1 of 1 (583 views)
Adding header to STDERR, STDIN & STDOUT Can't Post

Hi, Iím creating a perl script that takes incoming http/s requests, logs the standard input, output and error, before returning the output to the client. The input, output and error log is appended after each HTTP request.

The problem Iím having is that Iím trying to add a header line to the log files each time they are appended. For example if a new http request is made, a header will be added to each of the logs before the new standard data is added. This will most likely contain the ď$dateĒ and ď$timeĒ to enable the user to locate their most recent http request in the logs.

I am unsure how to add this header before the STDERR, STDIN and STDOUT are sent to their corresponding logs. Can anyone point me in the right direction? Any help would be much appreciated. Thanks.


#!/usr/local/bin/perl -w

use CGI qw(:standard);

use Cwd;

#Get the current date & time

($Second, $Minute, $Hour, $Day, $Month, $Year) = localtime(time);

$Year += 1900;


$date = "$Day.$Month.$Year";

$time = "$Hour:$Minute:$Second";

#Send the standard Error, Input and teed output to a log file

open (STDERR, ">> /tmp/$date-error.log") or die "can't connect to error.log: $!";

open (STDIN, ">> /tmp/$date-input.log") or die "can't connect to input.log: $!";

open (STDOUT, "| tee -a /tmp/$date-output3.log") or die "Can't connect to output.log: $!";

#Get the current working directory

$cgi_dir = getcwd();

# Serve the user

$result = system($cgi_dir . "/test-cgi");

exit $result;

#Close the standard output, input and error

close(STDERR) or die "Can't close error: $!\n";

close(STDIN) or die "Can't close input: $!\n";

close(STDOUT) or die "Can't close output: $!\n";



Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives