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:
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:$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'); }
Can anyone help me out?system("mysql < $FILE 2>> errorlog"); system("mysql < $FILE 2&>> errorlog");
20041011 Edit by ysth: add p and code tags
In reply to Need to capture return code by James_Marcinek
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |