I'm running a command on loads of NT boxes to map a drive. Sometimes it fails. Actually loads of times it fails (I love NT) for lots of different reasons - I'm trying to get the error produced so I can fix them but having loads of difficulty. I wrote the following test to test what error is produces
undef $^E; undef $!; undef $?; print "using system \n"; system("net use v: \\\\SERVERNAME\\SHARENAME"); print "dollar caret E reports $^E \n"; print "dollar Exclamation mark reports $! \n"; print "dollar question mark reports $? \n"; print "using backticks \n"; `net use v: \\\\SERVERNAME\\SHARENAME`; print "dollar caret E reports $^E \n"; print "dollar Exclamation mark reports $! \n"; print "dollar question mark reports $? \n";
What I get is this (I'v formatted it a bit to make it a little more readable.)
using system System error 85 has occurred. The local device name is already in use. dollar caret E reports The system cannot find the file specif +ied dollar Exclamation mark reports dollar question mark reports 512 using backticks System error 85 has occurred. The local device name is already in use. dollar caret E reports The pipe has been ended dollar Exclamation mark reports dollar question mark reports 512
What I really want is the english readable message eg System error 85 has occurred.The local device name is already in use. I think this is coded somehow in $? but my brain hurts and I can't figure it out. Has anyone any hints, tricks or a suggestion of where I should be looking for the answer?

In reply to capturing error messages from backticks or system by Piercer

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.