Connecting Tech Pros Worldwide Forums | Help | Site Map

how to detect broken pipe ?

funtoosh
Guest
 
Posts: n/a
#1: Jul 19 '05
Hi

Scenario:

I have a shell script e.g. a.bash
This script wraps a program called "generate" like this:

generate > /tmp/y.txt 2>&1 # both stdout and stderr r redirected to
y.txt

Now , I have perl script e.g. myPerl.pl and I modify a.bash such that:

generate | perl myPerl.pl # pipe output from "generate" to the perl
script.

And in myPerl.pl, I wrote this :

sub whatSignal { print "caught ",shift, "\n" };
$SIG($_}=\ &whatSignal for keys %SIG

And now I run a.bash in one xterm:
Following happens:
When press ctrl-C, it is caught.

But when I kill pid of program "generate" from a different xterm, my
script doesnt detect "broken pipe" ?

Comments ?

Ben Morrow
Guest
 
Posts: n/a
#2: Jul 19 '05

re: how to detect broken pipe ?



a_gilotra@yahoo.com (funtoosh) wrote:[color=blue]
> generate | perl myPerl.pl # pipe output from "generate" to the perl
> script.
>
> And in myPerl.pl, I wrote this :
>
> sub whatSignal { print "caught ",shift, "\n" };
> $SIG($_}=\ &whatSignal for keys %SIG[/color]

You only get sent SIGPIPE when you write to a broken pipe. Reading
will simply return EOF.

This Is Not A Perl Question.

Ben

--
. | .
\ / The clueometer is reading zero.
. .
__ <-----@ __ ben@morrow.me.uk
Closed Thread