Problem in printing a file created in the same script(redirecting output)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pnsreee
    New Member
    • Apr 2007
    • 34

    Problem in printing a file created in the same script(redirecting output)

    Hi All,

    I am trying to print a log file created in the same script with the code bellow.
    but Im not getting output on screen.
    The output file is created using rediretion of output.
    Code:
    open(STDOUT, ">flat.log") || die "Can't redirect stdout";
    
    prinf " ----------------------------------------------\n";
    printf " xyz ";
    prinf " ----------------------------------------------\n";
    
    close STDOUT;
    open(STDOUT, '>/dev/tty') or die "Can't restore stdout: $!";
    my $count;
    $count = 0;
    my @data;
    my $line;
    open(FILE, "< flat.log") or die "can't open file: $!";
    $count++ while <FILE>;
    @data = <FILE>;
    close (FILE);
    #open(STDOUT, '>/dev/tty') or die "Can't restore stdout: $!";
    if ( $count > 45 ) {
    
                    print " See the log file for details. \n";
            }else {
    
            print "@data";
            
    }
    please help me regarding this.

    Regards
    Naveen.
  • miller
    Recognized Expert Top Contributor
    • Oct 2006
    • 1086

    #2
    Hi Naveen,

    While it is possible to do what you are trying with much more advanced knowledge of file globs, my advice to you is to stop trying to redirect STDOUT. There is never a good reason to do this other than laziness, so just specify your output handles in your print statements:

    Code:
    open(LOG, ">flat.log") or die "Can't open flat.log: $!";
     
    print LOG " ----------------------------------------------\n";
    print LOG " xyz ";
    print LOG " ----------------------------------------------\n";
     
    close LOG;
    - Miller

    Comment

    • pnsreee
      New Member
      • Apr 2007
      • 34

      #3
      Hi Miller,

      I got output between 10 to 1000 lines.it is not possiable to moniter all lines on screen at a time.so that im trying to redirect it. If lines are less then 40, then I want to print the output on screen.

      Regards
      Naveen

      Comment

      • pnsreee
        New Member
        • Apr 2007
        • 34

        #4
        Hi Miller,
        I got the requried out put.

        Regards
        Naveen.P

        Comment

        Working...