473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding header to each standard output

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;
$Month++;
$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";
************************************************** ***************************
Sep 9 '07 #1
2 2076
KevinADC
4,059 Expert 2GB
I don't understand. Your code appears to print nothing to the STDIN and STDERR filehandles. It only opens them. Are you trying to put a new header as the first line of the files? Or what?
Sep 10 '07 #2
KevinADC
4,059 Expert 2GB
You should probably close the filehandles before issuing an "exit" command. I am not sure if perl will close those files or not before the script actually exits, but it seems safer to close the files and then do your other stuff.
Sep 10 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: exits funnel | last post by:
Hello, I'm trying to append the ascii representation of an integer to an stl string and I'm having some trouble. I've got the following bits of code: #include <string> #include <cstdlib> ...
0
by: Luke Airig | last post by:
I am using the Saxon engine and I have an xml file that contains batches of records. Each batch starts with a header record and the associated detail records immediately follow each header. There...
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
13
by: giovanniparodi79 | last post by:
Hello everybody is there some utility to convert a raw image in an header file? Thanks everybody Gio
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
19
by: Justin | last post by:
Harlow... i need some help on these... im actually trying to do a page using php... the function is to receive certain parameters from a 3rd party provider... and i need to redirect my page to...
16
by: wdh3rd | last post by:
Hi everyone. I'm new to C and I have a few questions: I am making files for permutations and combinations. Files to be made are perm.c, perm.h, combo.c, and combo.h. Since both combinations...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.