how to detect broken pipe ?

Discussion in 'Perl' started by funtoosh, Dec 20, 2003.

  1. funtoosh

    funtoosh Guest

    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 ?
    funtoosh, Dec 20, 2003
    #1
    1. Advertising

  2. funtoosh

    Ben Morrow Guest

    (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.
    . .
    __ <-----@ __
    Ben Morrow, Dec 21, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Clive
    Replies:
    0
    Views:
    2,992
    Clive
    Aug 12, 2003
  2. Tomas Penc
    Replies:
    3
    Views:
    35,890
  3. Jon Wayne
    Replies:
    0
    Views:
    530
    Jon Wayne
    Jun 29, 2004
  4. lee, wonsun
    Replies:
    1
    Views:
    477
    Jack Klein
    Nov 2, 2004
  5. Replies:
    1
    Views:
    212
    Ben Morrow
    Jun 2, 2004
Loading...

Share This Page