You are correct, my code does not explicitly right to STDOUT.  This was an
easy solution for me.  All I had to do was redirect STDOUT to a file and
this worked perfectly.  Here is what I used.

Open(STDOUT,"$filename");

I just added this to my script, and called my subs as normal and voila.  

Thanks to everyone who posted comments.

Joshua Scott
Security Systems Analyst, CISSP

-----Original Message-----
From: Jenda Krynicky [mailto:[EMAIL PROTECTED]] 
Sent: Friday, January 10, 2003 7:04 AM
To: [EMAIL PROTECTED]
Subject: RE: Perl Subroutines


From: "Scott, Joshua" <[EMAIL PROTECTED]>
> Let me add a little more info regarding my question.  The subroutines 
> are already setup and can't be modified easily.  The basic task of all 
> the different subs is to print to STDOUT.  I'd really like to be able 
> to call this sub from another script and somehow redirect the output 
> to a file without modifying the subs code.

Most probably they do NOT write to STDOUT, but to the currently 
selected filehandle. That is they contain
        print "Something\n";
and not
        print STDOUT "Something\n";

In this case all you have to do is to select() a different 
filehandle.

        open OUT, '> '.$filename or die "Can't open $filename : $!\n";
        {
                my $oldfh = select(OUT);
                call_the_procedure(params);
                select($oldfh);
        }
        close OUT;

See
        perldoc -f select

If the functions really write to STDOUT you may either:

        {
                local *STDOUT; # the "redirection" is only local
                open STDOUT, '> '.$filename or die "Can't open $filename :
$!\n";
                call_the_procedure(params);
                close STDOUT;
        }

or
        {
                local *OLDOUT; # to store the STDOUT
                open OLDOUT, '>&STDOUT' or die "Can't dup the STDOUT :
$!\n";
                close STDOUT;
                open STDOUT, '> '.$filename or die "Can't open $filename :
$!\n";
                call_the_procedure(params);
                close STDOUT;
                open STDOUT, '>&OLDOUT' or die "Can't restore the STDOUT :
$!\n";
        }

The second would be necessary if the procedure executes some external 
programs that need to be able to print to the same filehandle.

In either case make sure you restore the original STDOUT and/or 
selected flehandle.

HTH, Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
        -- Terry Pratchett in Sourcery


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


======================================================================================
NOTICE - This communication may contain confidential and privileged information that 
is for the sole use of the intended recipient. Any viewing, copying or distribution 
of, or reliance on this message by unintended recipients is strictly prohibited. If 
you have received this message in error, please notify us immediately by replying to 
the message and deleting it from your computer.

==============================================================================


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

Reply via email to