on Thu, 11 Jul 2002 15:49:59 GMT, Mark Henry wrote:

> I want a script to print log messages to a file, and within the same
> statement, to the screen (STDOUT) simultaneously.  Can the print
> statement be coerced into doing this, or is there another way of
> achieving the same result?

If you have tee, you can use:

    #! /usr/bin/perl -w
    use strict;

    open(STDOUT, "| tee log.txt") or die "Couldn't fork tee: $!";

    print "$_\n" for (1..10);

    close(STDOUT);

If you don't have tee, you will have to do the work yourself, e.g. like

    #! /usr/bin/perl -w
    use strict;

    open LOG, ">log2.txt" or die "Cannot open logfile: $!";

    myprint(*LOG, "$_\n") for (1..10);

    sub myprint {
        my $handle = shift;
    
        foreach my $fh (*STDOUT, $handle) {
            print $fh @_;
        }
    }

-- 
felix

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to