Hello Everyone,

I'm trying to figure out how to capture the return code of the previous command. The command is being invoked by the system call. I'm importing large amounts of data into a MySQL database. I'm having to convert logfiles for importation into the database. The original file was over 2 Gig so it was hard to look for out of the ordinary patterns... I had to split the files as it was causing MySQL to error out. I created a perl script (shown below) that will import the files then sleep for 5. As there are over 2300 files I need to know which ones are balking:

$LIST_FILE="listfile2"; open(LISTFILE, "$LIST_FILE") or die "Can't open the file.\n"; while(<LISTFILE>) { $FILE=$_; # Let's do it print "Importing $FILE.\n"; system("mysql < $FILE"); print "Sleeping for 5.\n"; system('sleep 5'); }
This actually is being run on an NT system where the database resides (I've set up a Samba share). I know both Windows shell scripting and Unix shell scripting. I'm aware of both the %ERRORLEVEL% and $? values but do not know if these will work. I thinking simplicity here. If the exit code is other than zero, then write the name of the file to a log file (a bonus would be to acutally capture the error itself). I had tried to redirect both 2>> errorlog and 2&>> errorlog in the:
system("mysql < $FILE 2>> errorlog"); system("mysql < $FILE 2&>> errorlog");
Can anyone help me out?

20041011 Edit by ysth: add p and code tags


In reply to Need to capture return code by James_Marcinek

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.