Got it FINALLY !

#!/usr/local/bin/perl5.005 -w
use strict;
use IO::Tee;
use IO::File;
my $tee;

&a;
print "this goes to a\n";
close MY_STDOUT;
$tee->close();

&b;
print "this goes to b\n";
close MY_STDOUT;
$tee->close();

&c;
print "this goes to c\n";
close MY_STDOUT;
$tee->close();

&d;
print "this goes to d\n";
close MY_STDOUT;
$tee->close();
sub a
{
  open MY_STDOUT , ">&STDOUT";
  $tee = new IO::Tee(\*MY_STDOUT
                    ,new IO::File(">a.out")); 
  select $tee;                     
}

sub b
{
  open MY_STDOUT , ">&STDOUT";
  $tee = new IO::Tee(\*MY_STDOUT
                    ,new IO::File(">b.out"));  
  select $tee;                      
}

sub c
{
  open MY_STDOUT , ">&STDOUT";
  $tee = new IO::Tee(\*MY_STDOUT
                    ,new IO::File(">c.out"));  
  select $tee;                     
}

sub d
{
  open MY_STDOUT , ">&STDOUT";
  $tee = new IO::Tee(\*MY_STDOUT
                    ,new IO::File(">d.out"));  
  select $tee;                     
}



Vaideeswaran S wrote:
> 
> My 2 cents:
> 
>  (a)  The reason for `close TEE' hangs could be due to inhertiance of
>       UNIX behaviour. E.g: take the below process
> 
>          % perl -e '1 while print "1\n"' | tee a.out
> 
>       If you kill the tee process, even the perl process get
>       killed. i.e if you close TEE, it expects source process
>       also to get closed. I think you can co-relate now!
> 
>  (b)  The solution is to revert back to STDOUT after closing ( same as
>       Vivek Dasmohapatra's point)
> 
>       open(STROUT, ">&STDOUT");                  <=== **NOTE**
>       &a
>       ....
>       close(STDOUT); open(STDOUT, ">&STROUT");   <=== **NOTE**
>       close(TEE);
>       &b
>       print(..);
>       ....
> 
> Regards,
> 
> Vaideeswaran S                    phone: 91 80 5099650
> EDA Engineer, DSP Design,         email: [EMAIL PROTECTED]
> Texas Instruments India
> Bangalore - 560 017
> 
> ---- Original Message ----
> 
> Here is a piece of code that I have tried to
> reproduce my problems.  What is not in the code is that
> I have some XS that is also spitting to stdout, so select $fh
> will not give me what I must have.
> 
> #!/usr/local/bin/perl5.005 -w
> use strict;
> 
> &a;
> print "this goes to a\n";
> close STDOUT;
> close TEE;
> &b;
> print "this goes to b\n";
> close STDOUT;
> close TEE;
> &c;
> print "this goes to c\n";
> close STDOUT;
> close TEE;
> &d;
> print "this goes to d\n";
> close STDOUT;
> close TEE;
> 
> # this prints only "this goes to a" to stdout
> # all other lines get printed to file, twice.
> 
> # if I remove the close STDOUT it hangs at the first close TEE
> 
> # if I remove all close statements and let the systems
> # close TEE automatically because it is being used again
> # I get a lockup on &b.  I'm guessing it is where the system
> # is trying to close the already open TEE
> 
> #So how do I open STDOUT after it has been closed?
> # do I get the tty and open it to that?
> # is there some other way to reopen STDOUT?
> 
> # the end must be that a copy of each line
> # gets printed to screen and to file.  I have
> # to maintian the files for proof of execution
> # for ??(days,weeks,months,years) to come.
> 
> # what my options are NOT:
> # 1. Rewriting my c library in perl
> # 2. Splitting up ALL subroutines into programs
> #    so that `prog 2>1&` or whatever will work
> # 3. Just forgetting about.
> 
> # Is there a c subroutine that I can get that will
> # do the above? if someone knows of such critter
> # I'll make a module of it.
> 
> sub a
> {
>   open TEE , "|tee a.out";
>   open STDOUT , ">&TEE";
> }
> 
> sub b
> {
>   open TEE , "|tee b.out";
>   open STDOUT , ">&TEE";
> }
> sub c
> {
>   open TEE , "|tee c.out";
>   open STDOUT , ">&TEE";
> }
> sub d
> {
>   open TEE , "|tee d.out";
>   open STDOUT , ">&TEE";
> }
> 
>  ========+=========+=========+=========+=========+=========+=========+
>    ___  _ ____       ___       __  __
>   / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___
>  / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
> /____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
>            /___/
> Texas Instruments ASIC Circuit Design Methology Group
> Dallas, Texas
> 214-480-4455
> [EMAIL PROTECTED]
> =========+=========+=========+=========+=========+=========+=========+
> 
> --
> "Stay committed to your decisions, but stay flexible in
> your approach." -- Anthony Robbins
> 
> email: [EMAIL PROTECTED]                    phone: 91 80 5099650

-- 
=========+=========+=========+=========+=========+=========+=========+
   ___  _ ____       ___       __  __          
  / _ )(_) / /_ __  / _ \___ _/ /_/ /____  ___ 
 / _  / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/   \_,_/\__/\__/\___/_//_/
           /___/                               
Texas Instruments ASIC Circuit Design Methology Group
Dallas, Texas
214-480-4455
[EMAIL PROTECTED]
=========+=========+=========+=========+=========+=========+=========+

Reply via email to