The close command returns the exit status of the piped command.

If the piped command has exited with status=0 before close is called, then close will succeed.

If it exits with status != 0 before close is called, then close will fail and $? will equal the exit status.

If close is called before the piped command exits, then close will fail and $? will equal SIGPIPE. Why? Because Perl sends SIGPIPE to the piped command, then waits for it to exit, and then grabs its exit status which is the signal caught by the piped command (i.e., SIGPIPE). (Note that it is possible for the piped command to intercept the SIGPIPE signal and exit with some other exit status (e.g., exit 0) which will be picked up instead.)

In the case you experienced with the web server, it may be that the CGI is getting to the close command before the piped command actually exits. If you insist on testing the status of the close command, then modify your piped command to intercept SIGPIPE and terminate with a 0 exit status.


Remember: There's always one more bug.

In reply to Re: "close" failing by jdhedden
in thread "close" failing by munishdev

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.