On Fri, 16 Jan 2004, Larry Guest wrote:
> I have a small script that does some admin work for me.
>
> What I need to do now is not only have is display information to STDERR
> and STDOUT but also write the same information I see when I run the
> command to a file.
>
> I have written it for others who are not very technical. I want them to
> be able to see the script working and what it is doing. But I also need
> a log file of the same information so I can have it mailed to me and
> keep a copy on the server.
>
> I cant seem to get this to work.
>
What have you tried? I would alter the script to have multiple print
statements. One to STDERR or STDOUT, the other to my file. Something like:
open(LOGGER,'myfile.log');
...
print STDERR "$message\n";
print LOGGER "$message\n";
...
If you want, you could "encapsulate" this by not using print directly, but
in your own function, say "myprint()".
sub myprint {
my $fn = shift;
print $fn "@_";
print LOGGER "@_";
}
my $STDOUT=\STDOUT;
my $STDERR=\STDERR;
...
my $message="This is a test.\n";
...
&myprint($STDOUT,$message);
...
&myprint($STDERR,$message);
Hope this is useful in some way.
--
Maranatha!
John McKown
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>