469,898 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,898 developers. It's quick & easy.

how to detect broken pipe ?

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 ?
Jul 19 '05 #1
1 8884

a_*******@yahoo.com (funtoosh) wrote:
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


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.
. .
__ <-----@ __ be*@morrow.me.uk
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Frank de Bot | last post: by
1 post views Thread by Ruben | last post: by
2 posts views Thread by Nigel King | last post: by
4 posts views Thread by Pascal Ehlert | last post: by
6 posts views Thread by Tim Chase | last post: by
2 posts views Thread by Robin Becker | last post: by
1 post views Thread by Christoph Krammer | last post: by
11 posts views Thread by 7stud | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.