Hello Brothers,

I'm quite new to doing IPC work in Perl, and I'm having a devil of a time handling errors. For example, I do this, using IPC::Open3:

my $pid = open3( $wtr, $rdr, $err, $httpd, '-v' ); my ($version, $builtondate) = <$rdr>;
and that works just fine--when the binary is correctly specified in $httpd. If I move the binary out of the way for testing so that the call will fail, I get errors spewed to my terminal about undefined variables and such, which I would expect.

So I would like to trap the failure. What I understood from the cpan page for IPC::Open3 is that errors would be written to the $err filehand however if I do this:

print readline $err;
when I've moved the httpd binary out of the way, I get this error from my script:
Use of uninitialized value in <HANDLE> at ./test.pl line 248. readline() on unopened filehandle at ./test.pl line 248.
Shouldn't the failure to execute httpd have been printed to that $err filehandle so that I can trap it? Or is that just for errors from the executed process itself?

I've tried all kinds of gymnastics using backtick shell commands, pipes, etc. but haven't found a way to trap the failure to execute.

Any input would be greatly appreciated!


In reply to Error handling in Inter Process Communication by rastoboy

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.