James_Marcinek has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Need to capture return code
by Roy Johnson (Monsignor) on Oct 11, 2004 at 19:00 UTC | |
|
Re: Need to capture return code
by pg (Canon) on Oct 11, 2004 at 19:45 UTC | |
by James_Marcinek (Initiate) on Oct 11, 2004 at 19:59 UTC | |
|
Re: Need to capture return code
by periapt (Hermit) on Oct 12, 2004 at 12:31 UTC | |
|
Re: Need to capture return code
by dragonchild (Archbishop) on Oct 11, 2004 at 18:33 UTC | |
by James_Marcinek (Initiate) on Oct 11, 2004 at 18:45 UTC | |
by dragonchild (Archbishop) on Oct 11, 2004 at 19:03 UTC | |
by James_Marcinek (Initiate) on Oct 11, 2004 at 19:19 UTC | |
by dragonchild (Archbishop) on Oct 11, 2004 at 19:26 UTC | |
|