SPUG:Broken Pipe

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Mon Mar 17 16:42:13 CST 2003


> This is sort of a unix question and sort of a perl question, but does anybody know how to get rid of the annoying Broken Pipe message that occurs when I run a system command from within my script and then interrupt the system call in the middle. I'm doing a traceroute and I want to interrupt the trace if it returns "* * *", but when I do that it returns "Broken Pipe".
> 
> Code snippet:

>   open( TRACE, "$TRACE $ip 2>/dev/null |" ) or return;

>   while (<TRACE>) {
>         s/\s+//;
>         if (/^\d+\s+(.*)\s+\((\d+\.\d+\.\d+\.\d+)\)\s+/) {
>             my $name = $1;
>             my $ip   = $2;
>             if ( $name eq $ip ) {
>                 push @route, $name;
>             } else {
>                 push @route, "$name-$ip";
>             }
>         }
>         if (/\*\s+\*\s+/) {
>             push @route, "*-*-*-*-*";
>             last;
>         }
>     }
>     close(TRACE);
> 
> Anyone have any ideas why Broken Pipe occurs and how to get rid of it? I'm running this on a Solaris machine (2.5.1 OS - please don't ask why). I think it is a OS issue because if I run it on an HP-UX 11.00 machine (again, I won't answer why) there are no Broken Pipe statements. 

Not sure why .. but one end of the pipe is probably 
complaining because the pipe gets closed prematurely, 
i.e, there's still data to be read trickling down the
pipe but the pipe's already been closed. Maybe the
geriatric OS version is part of the problem... 

The close(TRACE) should drain any data that's left 
before the pipe is closed. You might try checking 
the error just to understand more thoroughly what's 
happening.

Here's a snippet adaption from  the 'close' docs (also
take a look at perlipc): 

   close OUTPUT   # wait for traceroute to finish
       or warn $! ? "Error closing pipe: $!"
                  : "Exit status $? from traceroute ;

You could probably localize sigpipe to stop the noise 
(if  everything else's working and this is just a fly
 buzzing around the head of your perfectly working 
 program ).

  { local $SIG{PIPE} = 'IGNORE'; ... }


HTH,
--
Charles DeRykus  



More information about the spug-list mailing list