Hi,

I already tried IO::Tee. This does not solve my
purpose.

Again, I am describing my problem in two parts:

1. I am getting messege outputs from a program, which
I am calling in perl script. This program is putting
all the message. Hence I need to TEE the STDOUT with
some file.

STDOUT --------> STDOUT
           |---> <foo_1.txt>, <foo_2.txt>, <foo_3.txt>
2. I want to write a selected portion of STDOUT to a
specific file.
   In case I am using
           my $sFile = "foo_" . $cnt . ".txt"
           open(STDOUT, "| tee $sFile");
           First files get all the output till end
after it is opened (as mentioned below).

Waiting for more suggestions for same.

Thanks and regards
Ambikesh

--- zentara <[EMAIL PROTECTED]> wrote:
> On Thu, 7 Apr 2005 05:53:04 -0700 (PDT),
> [EMAIL PROTECTED] (Ambikesh
> Chaurasia) wrote:
> 
> >I am calling 2 programs from my perl script. Output
> of
> >these program is being displayed in STDOUT.
> >I want to display this outout in STDOUT as well as
> >want to log output of each program in separate
> files.
> >How to do this?
> >
> >In order to do above, I tried following program:
> >#!/usr/bin/perl -w
> >use strict;
> >
> >print "Started the file write\n";
> >for (my $cnt=0; $cnt < 4; $cnt++)
> >{
> >my $sFile = "foo_" . $cnt . ".txt";
> >open STDOUT, "| tee $sFile" ;
> >print $sFile, " ", $cnt, "\n";
> >#close(STDOUT);
> >}
> >
> >1. Problem in above program is that foo_0.txt have
> all
> >the output in this (as given below)
> >foo_0.txt 0
> >foo_1.txt 1
> >foo_2.txt 2
> >foo_3.txt 3
> >
> >2. Other problem is that I am able to close the
> STDOUT
> >or not able to dis-link file $sFile.
> 
> Here are some general ideas, 
> #################################################3
> #!/usr/bin/perl
> use IO::Tee;
> 
> $tee = IO::Tee->new($handle1, $handle2);
> print $tee "foo", "bar";
> 
> ############################################### 
> $tee = IO::Tee->new(\*STDOUT, \*OUTFILE);
> print $tee "Your data here" if 1;
> 
> ############################################## 
> 
> #roll your own 
> open my $fh, ">test.out" or die "Can't open
> outfile.";
> print $_ "Test string.\n" for \*STDOUT, $fh;
> close $fh;
> ##############################################
> 
> Using the "roll-your-own" approach:
> ###############################################
> #!/usr/bin/perl
> use warnings;
> use strict;
> 
> print "Started the file write\n";
> 
> for (my $cnt=0; $cnt < 4; $cnt++)
>    {
>      my $sFile = "foo_" . $cnt . ".txt";
>      open my $fh, ">$sFile" or die "Can't open
> $sFile, $!\n";
> 
>      for my $filehandle(\*STDOUT, $fh ){
>         print $filehandle "$cnt\n";
>         }
>      close $fh;
>   }
> 
> __END__
> 
> 
> 
> 
> 
> 
> 
> 
> -- 
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> <http://learn.perl.org/>
> <http://learn.perl.org/first-response>
> 
> 
> 


                
__________________________________ 
Do you Yahoo!? 
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to