MAPEXE (with those arguments) is run whenever you execute a PATH command.
Well that's interesting. I'm definitely not
trying to execute a PATH command.
I'm going to assume two things (1) There are no other situations where MAPEXE would be run with (with those arguments) and (2) MAPEXE wouldn't be run twice in a row as shown in the log unless I somehow triggered a PATH command twice. Rex - please let me know if these assumptions are incorrect.
Here's a little bit more about my actual problem situation. I am running an unattended BTM which is started from Task Scheduler in the middle of the night and running in TCC (no Take Command). It runs some custom backup logic and then when complete copies any updated backup files to an external USB drive (or two, but who's counting).
There were times when the backups were created and some but not all of the copying to the backup drives happened. It didn't always end at the same place, or with the same drive, but it was always stopping somewhere in the series of copy commands.
I suspected that there may have been some sort of sporadic error in the copy process (maybe USB drives starting to fail) which caused this. I added an ON ErrorMsg command before each copy which would call a subroutine to log the location where the Error occurred.
Now when an error occurs (not reproducible) the script never reaches it's normal conclusion. I turned on Command Logging and that's when I saw that when the script failed to complete, the original BTM was re-executed from the top, but without the expected command line parameters. This resulted in the second invocation displaying some syntax help and quitting.
Now I'm wondering if somehow the construct I am using for ON ErrorMsg might be in part to blame.
Here's the simplest .BTM I could come up with that mirrors the essential elements of my original .BTM
Code:
@echo off
iff %# == 0 (echo No Parameters & quit)
echo. & echo.
echo ------------------------------------------------------------------
echo ------ Create error without redirection --------------------------
echo ------------------------------------------------------------------
on errormsg (gosub LogCmdError "DivBy0" %_? %@execstr[caller 0])
set TestNum=%@eval[10/0]
echo. & echo.
echo -------------------------------------------------------
echo ------ Create error WITH TEE --------------------------
echo -------------------------------------------------------
on errormsg (gosub LogCmdError "Divide by Zero" %_? %@execstr[caller 0])
echo %@eval[10/0] |& tee /a "D:\BackupLogs\TestErrorMsg4.log"
REM Original Command which sometimes fails
REM *copy /u /e "D:\Backup4All-Backups (DESKTOP-ABCDEFG)\$WebPages - $Archive\*.*" "I:\DESKTOP-ABCDEFG-Backup\Backup4All-Backups (DESKTOP-ABCDEFG)\$WebPages - $Archive\" |& tee /a "D:\BackupLogs\TestErrorMsg3.log"
echo. & echo.
echo ---------------------------------------------------------------------------------------------------
echo ------ Try Original Command with /N added and invalid destination drive to make it fail -----------
echo ---------------------------------------------------------------------------------------------------
on errormsg (gosub LogCmdError "Copy Error" %_? %@execstr[caller 0])
*copy /n /u /e "D:\Backup4All-Backups (DESKTOP-ABCDEFG)\$WebPages - $Archive\*.*" "Q:\DESKTOP-ABCDEFG-Backup\Backup4All-Backups (DESKTOP-ABCDEFG)\$WebPages - $Archive\" |& tee /a "D:\BackupLogs\TestErrorMsg4.log"
echo.
quit
:: ===================================================================================================================
::
:LogCmdError [pErrType pRetCd pLine pRoutine pFileName*]
::
:: ===================================================================================================================
REM --------- Should be called from an ON ERRORMSG with a command such as
REM --------- on errormsg (gosub LogCmdError "Functionality Error" %_? %@execstr[caller 0])
REM ---------
REM --------- Note: pLine, pRoutine, pFileName will all be returned by "Caller 0" command
REM ---------
REM --------- Note: If ErrorLog environment variable is set, messages will be redirected there. Else they will display on screen.
REM ---------
echo *** Entering LogCmd error subroutine
set LCE_ErrLoc=%@Quote[%pFileName] Line:%pLine %@if[%pRoutine != main, (SubRoutine:%pRoutine),``]
if Defined ErrorLog (set LCE_ErrorLog=%ErrorLog) ELSE (set LCE_ErrorLog=CON)
echo. >> %LCE_ErrorLog
echo ERROR: %pErrType encountered in %LCE_ErrLoc Return Code: %pRetCd >>%LCE_ErrorLog
echo Check %@Quote[%LCE_ErrorLog] for details. >>%LCE_ErrorLog
unset /Q LCE_ErrLoc LCE_ErrorLog
return
When I run this test script everything works as expected.
But when my real script runs, sometimes (I think it's when a Copy command encounters an error), the LogCmdError subroutine is not executed.
Instead, the original .BTM is reinvoked without any parameters, and for some reason TCC sees [two?] PATH commands.
Does anything I'm doing look like it could generate that outcome?
I'm suspicious that this might be caused by my code, since the Caller command will return the full path of the script without parameters...but my test script works reliably, and I can't see anything I'm doing to cause this.