> -----Original Message-----
> From: Patrick K Christopher TANAGER 
> [mailto:pchristop...@tanagerinc.com] 
> Sent: Tuesday, July 21, 2009 11:04
> To: Wagner, David --- Senior Programmer Analyst --- CFS; Tony 
> Esposito; beginners@perl.org
> Subject: RE: Having problems getting data back to STDOUT once 
> I assign it to a file
> 
> 
> 
> This is how I got it to work. However any STDOUT completion 
> messages will need to be done outside the brace.
> 
> }
> 
> local *STDOUT;

        Ok, that seems do it. I have for the most part never used or
needed the *xxxxx notation, so though I have been using Perl for years,
not sure of all that it implies. 

        So here is what I did:

if ( $GlblInfo{audit} ) {
    print "All STDOUT/STDERR will be assigned to this scripts audittrail
log!!\n"x3;
    open(OLD_STDERR,">&STDERR") or die "Failed to save STDERR"; #pulled
this from the internet
 }
        If I do not do this before the print, then I get print on a
closed filehandle.

    local *STDOUT;
Then I placed the code to capture the STDOUT/ERR to a file. This worked
as expected and placed all that was being displayed to the screen to
disk.

        I then had the following:
    if ( $GlblInfo{audit} ) {
        print "\n\n*****Should be last line in the audittrail
file...*****\n\n";
        open(STDERR,">&OLD_STDERR") or die "Failed to restore STDERR";
        select(STDERR);
        open(STDOUT , '>-') || die "Unable to open STDOUT: $!";
        select(STDOUT);
        if ( $GlblInfo{continues} ) {
            print "\n\n" . "*EndOfProg*"x7 . "\n\n";
         }else {
            print "\n\n" . "**Error*"x9 . "\n\n";
         }
     }

        Now everything seems to be working as I would have expected. I
added an error to the open on STDOUT and it threw up the error to
STDERR.

        As to the printf verses print, sorry, but I am the only one
doing the work here using Perl. There may be overhead and I will try to
change the thought processes.

        I do appreciate the list and it's help..

        Thanks again.
         If you have any questions and/or problems, please let me know.
         Thanks.
 
Wags ;)
David R. Wagner
Senior Programmer Analyst
FedEx Freight Systems
1.719.484.2097 Tel
1.719.484.2419 Fax
1.408.623.5963 Cell
http://fedex.com/us 
        
> 
> if ( $GlblInfo{audit} ) {
>     printf "All STDOUT/STDERR will be assigned to this 
> scripts audittrail log!!\n";
>     printf "All STDOUT/STDERR will be assigned to this 
> scripts audittrail log!!\n";
>     printf "All STDOUT/STDERR will be assigned to this 
> scripts audittrail log!!\n";
>     open(STDOUT, q[>>] . $GlblInfo{audittrail}) || dies(0, 
> $GlblInfo{audittrail}, $!);
>     select(STDOUT);
>     $| = 1;
>     open(STDERR, q[>>] . $GlblInfo{audittrail}) || dies(1, 
> $GlblInfo{audittrail}, $!);
>     select(STDERR);
>     $| = 1;
>  }
> }
>         The sub dies is my own little setup.
> 
>         It does take all the output destined for STDOUT and 
> STDERR and places into a file. I have reviewed the output in 
> the file and it is what I expect.
> 
>         I am running under Xp SP2 using AS 5.8.9 Build 825 ( 
> Dec 2008 ). Running under a Korn shell, but have tried with 
> the std command shell with all the same results.
> 
>         I do not go into a loop, but I would never have 
> thought I would spend so much time for something so minor. At 
> this point, I have tried everything but the tee (tee is not 
> accomplishing what I wanted: off the screen and into a file) 
> and always with the same results: no more output to STDOUT or 
> STDERR. Everything that I read using perldoc and perliotut 
> says to do this and this and you will have STDIN or STDOUT. 
> Use '-' for STDIN and '>-' for STDOUT, but for whatever 
> reason or the way I am doing it, I never see anything printed out..
> 
>         At this point, I will leave it alone for a while and 
> see if anything else floats to the top.
> 
>         I appreciate all the responses, but never thought it 
> would be this complicated to just get back to a STDOUT or 
> STDERR.  It is Perl..
> 
>         Thanks.
> 
> Wags ;)
> David R. Wagner
> Senior Programmer Analyst
> FedEx Freight Systems
> 1.719.484.2097 Tel
> 1.719.484.2419 Fax
> 1.408.623.5963 Cell
> http://fedex.com/us
> 
> >
> > use File::Tee qw(tee);
> >
> > # simple usage:
> > tee(STDOUT, '>', 'stdout.txt');
> >
> > Tony
> >
> >
> >
> > ________________________________
> > From: John W. Krahn <jwkr...@shaw.ca>
> > To:
> > Sent: Tuesday, 21 July, 2009 8:41:25
> > Subject: Re: Having problems getting data back to STDOUT once
> > I assign it to a file
> >
> > Shawn H. Corey wrote:
> > > John W. Krahn wrote:
> > >> Shawn H. Corey wrote:
> > >>> Wagner, David --- Senior Programmer Analyst --- CFS wrote:
> > >>>>    I am done processing and I want to place the final
> > output line also on the screen. Here is what I have:
> > >>>>
> > >>>>    if ( $GlblInfo{audit} ) {
> > >>>>        printf "\n\n*****Should be last line in the
> > audittrail file...*****\n\n";
> > >>>>        close(STDOUT);
> > >>>>        close(STDERR);
> > >>>>        open(STDOUT , '>') || die "Unable to open STDOUT: $!";
> > >>>
> > >>> You're not opening STDOUT to anything.  And you closed
> > STDERR so the die message can't go anywhere.  In fact, it
> > goes into an infinite loop.
> > >>
> > >> No it doesn't, there is no loop there.
> > >
> > > It goes into an infinite loop on my machine.  I suggest you
> > try it before you make such blanket statements.
> >
> > I did and it doesn't on my machine.  Perhaps your OS or C
> > library is doing something stupid?  It makes no sense for IO
> > on an unopened filehandle to loop.
> >
> >
> >
> > John
> > -- Those people who think they know everything are a great
> > annoyance to those of us who do.        -- Isaac Asimov
> >
> > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > For additional commands, e-mail: beginners-h...@perl.org
> > http://learn.perl.org/
> >
> >
> >
> >
> 
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
> 
> 
> 
> This message contains confidential information and is 
> intended only for the individual named.  If you are not the 
> named addressee you should not disseminate, distribute or 
> copy this email.  Please notify the sender immediately by 
> e-mail if you have received this e-mail by mistake and delete 
> this e-mail from your system.  E-mail transmission cannot be 
> guaranteed to be secure or error-free as information could be 
> intercepted, corrupted, lost, destroyed, arrive late, or 
> incomplete, or contain viruses.  The sender therefore does 
> not accept liability for any errors or omissions in the 
> contents of this message, which arise as a result of e-mail 
> transmission.  If verification is required, please request a 
> hard-copy version.
> 
> Tanager, INC
> 3140 West Ward Road
> Suite 205
> Dunkirk, MD 20754
> www.tanagerinc.com
> 

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to