The real problem here is that the messages the shell gives are internal to the shell, and the code the shell chooses to return caller are chosen by the shell.

If the code returned translates directly into a 'system message', and the shell chooses to also report that 'system message', as in the case of "No such file or directory", then perl can translate the code into that same system message.

But, if the shell chooses, given it's intimate knowledge of what you asked it to do, and what error it encountered trying to do it, to report that at a level of detail, or in a manner that for which there is no convenient system message/code, then Perl cannot hope to translate the code returned into the same message the shell produces.

That's a long-winded way of saying, what you are asking for it probably not possible. Consider the case where you passed the same eroneous command to two different shells. Each will produce it's own message, with it's own level of detail. Each will choose what return code to pass back to Perl--they maybe the same or different. Unless they are consistant, and relate to some system message, Perl cannot translate it as you would wish.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

In reply to Re: Using system(): converting error num to human readable message by BrowserUk
in thread Using system(): converting error num to human readable message by chrism01

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.