Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Unexpected termination on "print" (pipe)

by mlawren (Sexton)
on Aug 14, 2015 at 20:35 UTC ( [id://1138639]=note: print w/replies, xml ) Need Help??


in reply to Re: Unexpected termination on "print" (pipe)
in thread Unexpected termination on "print"

Thanks for your reply tye. Much appreciated, especially given how deep these nodes get pushed with all the questions coming through.

I know in principle what $? is used for, but I could not find (nor does the documentation you point to) a list matching perl exit codes (or are they system error codes?) with reasons. Should I be looking at something like errno.h?

However your pointer to SIGPIPE was spot on. Installing a handler allowed me to deal with the error and continue execution.

Thanks again.

  • Comment on Re^2: Unexpected termination on "print" (pipe)

Replies are listed 'Best First'.
Re^3: Unexpected termination on "print" (docs)
by tye (Sage) on Aug 14, 2015 at 20:50 UTC
    Should I be looking at something like errno.h?

    No, you should be reading the documentation that I already linked to: $?.

    - tye        

      Hmm... perhaps you think I didn't read the documentation you linked to? I did, twice, but that didn't get me very far. Which either says something about my comprehension, or the quality of the documentation.

      $? is a perl variable. Presumably, in the case we are discussing, print/write to a closed pipe results in $? being set, and presumably that is also what perl ends up passing back to the shell, which shifts it by 8 and eventually I end up seeing it as an integer.

      How does the documentation for $? supposed to get me from the number 141 back to SIGPIPE?

      update: So it turns out the shell exit code is $? directly, and not shifted like I thought. Hence:

      141 >> 8 = 0 141 & 127 = 13 141 & 128 = 128
      And now I see that I have something I can look up in signum.h.
        Hmm... perhaps you think I didn't read the documentation you linked to? I did, twice, but that didn't get me very far.

        Then you seem to have a real problem reading the documentation. Read the first paragraph below $?, and especially its last sentence. This is the first paragraph:

        The status returned by the last pipe close, backtick (``) command, successful call to wait() or waitpid(), or from the system() operator. This is just the 16-bit status word returned by the traditional Unix wait() system call (or else is made up to look like it). Thus, the exit value of the subprocess is really ($? >> 8), and $? & 127 gives which signal, if any, the process died from, and $? & 128 reports whether there was a core dump.

        What part of it don't you understand?

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
        How does the documentation for $? ... So it turns out ...

        Since you did not find this info in the linked documentation, can you please, for the benefit of future Seekers of Wisdom, publish a link or some other reference to the documentation or source of information that you ultimately used?


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1138639]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-18 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found