Thanks guys. Thats what I was after. Maybe this is a stupid question, but
I'll ask it anyway...
Is there some way of  telling when an application is sending output to
STDERR and not STDOUT? Is it just a case of try STDERR if nothing on
STDOUT?




                                                                                       
                               
                    rotaiv <[EMAIL PROTECTED]>                                          
                               
                    Sent by:                                     To:     
[EMAIL PROTECTED]             
                    [EMAIL PROTECTED]        cc:                   
                               
                    eState.com                                   Subject:     Re: 
problem trapping command output     
                                                                                       
                               
                                                                                       
                               
                    06/28/2001 07:57 AM                                                
                               
                                                                                       
                               
                                                                                       
                               




For a quick answer, see below (taken from Perl Cookbook 16.7. Reading
STDERR from a Program):

@result = `c:\\gzip\\gzip.exe -d c:\\gzip\\readme.gz 2>&1`;
foreach $line(@result) {
   print "the output of the command is  $line";
}

(Note: I dropped the '\n' on the print line as the output usually has it's
own line feeds).

For a more detailed explanation, see below:

Each program has the capability of generating output to STDOUT and
STDERR.  By default, when you redirect output, you will only get
STDOUT.  The version of gzip that I use sends errors messages to STDERR and
not STDOUT.  Therefore, to capture STDERR on NT, you need to use the '2>'
redirection command.

NT also allows you to use the '&1' parameter to tell the second redirect
command to send the output where ever the first redirect command is sending
it's output.  For example, to log all output from gzip to a log file, you
would use the following:

   gzip.exe -d readme.gz > logfile.txt 2>&1

This tells NT to send STDOUT to logfile.txt and send STDERR to where ever
STDOUT is going (which in this case would also be logfile.txt).  Naturally,
UNIX shells have the same capability but the syntax changes depending on
what shell you are using.

rotaiv

At 06/27/2001  03:33 PM, [EMAIL PROTECTED] wrote:

>Hi,
>running winnt/2k AS perl build 623
>I've been ftp'ing files across a wan link, and unzipping them with gzip.
>Occasionally, the file gets corrupted. I wanted to add some error checking
>to my script to not try to process the file if gzip could not unzip it,
for
>whatever reason.
>
>so I tried doing something like this:
>
>@result = `c:\\gzip\\gzip.exe -d c:\\gzip\\readme.gz`;
>
>foreach $line(@result)
>    {
>       print "the output of the command is  $line\n";
>    }
>
>now readme.gz is a file I intentionally corrupted(to get output from
gzip).
>The output of gzip run against this file from the cmd line is:
>
>gzip: c:\gzip\readme.gz: invalid compressed data--crc error
>
>but the above code fragment produces no output.  I would have expected the
>print statement in the above code fragment to be executed.  Any clues
>appreciated.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to