At 05:29 PM 8/8/02 -0400, Sylvanie, Jean-Pierre wrote:
>Hi guys,
>
>Actually I want to get STDERR ouput to have more details about systems call
>errors, and write the result to a log file...
>
>I spent a couple of hours writing (well... Finding how to write ! :)
>the "sample code", but I have the feeling that all that stuff is overkill...
>Is there something more simple ?

Eek.  It seems to me that you could just do

         $output = `$cmd 2>&1`;

and then pattern match on $output after checking return status in $?.

>Thanks for your time !
>
>************
>SAMPLE CODE
>************
>#--------------------------------------------------------------------
># The following code is for reading STDERR output
># from a filehandle called GET_STDERR
>
># Opening a pipe to get STDERR output.
>pipe(GET_STDERR, FROM_STDERR) or die "pipe $!";
>
># setting GET_STDERR non blocking :
># we don't want to wait for data if nothing's ready
>my $flags = fcntl(GET_STDERR, F_GETFL, 0 ) or die "can't get flags";
>fcntl(GET_STDERR, F_SETFL, $flags | O_NONBLOCK) || die "can't set flags";
>
># setting autoflush to all STDERR related filehandles
>select((select(STDERR)      , $|=1)[0]);
>select((select(GET_STDERR)  , $|=1)[0]);
>select((select(FROM_STDERR) , $|=1)[0]);
>
># redirect STDERR to pipe input
>open(STDERR, ">&FROM_STDERR") || die "Can't dup stderr";
>
># buffer for reading pipe output
>my @err = ();
>
>
>#... bla bla bla ...
>
>     my $cmd = "$ZIP_CMD $filename";
>
>     if ( system($cmd) != 0 ){
>       chomp(@err = <GET_STDERR>);
>       log_("0310E-Can't zip file Cmd=[$cmd]; stderr=[".join("; ",@err)."]");
>     }
>
>#... bla bla bla ...
>
>#--------------------------------------------------------------------
>
>
>
>jp.
>---------------------------------------
>Jean-Pierre Sylvanie
>Microcell Telecom - IT Dev          (o_
>Assurance des Revenus & Fraudes     //\
>Revenue Assurance & Fraud           v_/
>(514) 937-0102 (ext: 6062)
>[EMAIL PROTECTED]
>---------------------------------------
>
>
>
>--
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]

--
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to