Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

MAPEXE commands executed at the start of a BTM - is that expected behavior?

Jun
149
13
I'm in the middle of trying to figure out a thorny, sporadic issue (more on that later) so I turned on Command Logging.

There's a point in the process where a running BTM script is re-executed from the start (could be self-inflicted). I noticed in command log that when this happens, there are 2 MAPEXE commands logged which are NOT in my BTM script.

Is this normal behavior, or could the fact that this is happening be an indication of something else wrong which might be relevant to my issue?

1786892611492.webp


I have tested with this simple testBTM1.BTM

Code:
@echo off
log /w "D:\BackupLogs\TCCommandLog(AftVarExp)_2.txt"
echo ---- In TestBTM1
if "%1" == "x" c:\batfile\testBTM1.btm

And the log does not show any MAPEXE commands being executed when the BTM is reinvoked.

Code:
[ 8/16/26 11:15:10a][32204]
[ 8/16/26 11:20:07a][25688] echo ---- In TestBTM1
[ 8/16/26 11:20:07a][25688] if "%1" == "x" c:\batfile\testBTM1.btm
[ 8/16/26 11:20:07a][25688] c:\batfile\testBTM1.btm
[ 8/16/26 11:20:07a][25688] echo off
[ 8/16/26 11:20:07a][25688] log /w "D:\BackupLogs\TCCommandLog(AftVarExp)_2.txt"
[ 8/16/26 11:20:07a][25688] echo ---- In TestBTM1
[ 8/16/26 11:20:07a][25688] if "%1" == "x" c:\batfile\testBTM1.btm
 
Last edited:
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.

1786909639226.webp


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.
 
Last edited:
(Just a guess) Rex might have meant when you execute a command that's found using the path.
 
Off Topic:

It is this type of information that I add to my RightNote TCC Help File.

Attached is the HTML page that RightNote generated.

It is the original TCC Help Page for MAPEXE,
along with the post made by Rex in this forum.

I also note in what version of TCC MAPEXE was introduced.

Hypelinks include the JPSoft Help Page for MAPEXE,
and the post made by Rex in this forum.

Joe
 

Attachments

I have NOT set the "Update Environment on System Change", nevertheless I have the mapexe command also in log, see here for example:

Code:
[17.08.26 00:38:13][8620] echo 0 >& nul:
[17.08.26 00:38:13][8620] doskey /macrofile=c:\ShellConfig\Alias\cmd_alias.lst
[17.08.26 00:38:13][8620] echo off
[17.08.26 00:38:13][8620] alias /r "c:\ShellConfig\Alias\tc_alias.lst"
[17.08.26 00:38:13][8620] if %_pipe EQ 1 quit
[17.08.26 00:38:13][8620] if %_transient EQ 1 quit
[17.08.26 00:38:13][8620] quit
[17.08.26 00:38:13][8620] "C:\Scripts\Sync-EXT_Cloud_4.btm"
[17.08.26 00:38:13][8620] echo off
[17.08.26 00:38:13][8620] cls
[17.08.26 00:38:13][8620] setlocal
[17.08.26 00:38:13][8620] iff not exist "c:\ShellConfig\Temp\BAK_Sync_Cloud__State.txt" then
[17.08.26 00:38:13][8620] ren /q "c:\ShellConfig\Temp\BAK_Sync_Cloud__State.txt" "c:\ShellConfig\Temp\BAK_Sync_Cloud__State_Runs.txt"
[17.08.26 00:38:13][8620] set key=c
[17.08.26 00:38:13][8620] echo ``
[17.08.26 00:38:13][8620] echo ^e[35;1mSync EXT Cloud S-4 ...^e[0m
[17.08.26 00:38:13][8620] echo ``
[17.08.26 00:38:13][8620] echo ^e[33;1mPlease wait and do not cancel the script,^e[0m
[17.08.26 00:38:13][8620] echo   ^e[33;1mexcept with "q" while the 5 secs waiting time now ...^e[0m
[17.08.26 00:38:13][8620] echo ``
[17.08.26 00:38:13][8620] inkey /k"cq" /w5 /T "c": continue; "q": quit/exit ("c" after 5 seconds):  %key
[17.08.26 00:38:13][8620] if "%key" == "c" goto Continue
[17.08.26 00:38:13][8620] goto Continue
[17.08.26 00:38:13][8620] on break gosub GotBreak
[17.08.26 00:38:13][8620] if not isdir "u:\_BAKs\CL5\" goto ErrorEnd2
[17.08.26 00:38:13][8620] if not isdir "r:\_BAKs\CL5\" goto ErrorEnd2
[17.08.26 00:38:13][8620] echo ``
[17.08.26 00:38:13][8620] robocopy "d:\CL5" "r:\_BAKs\CL5" /MIR /COPY:DAT /DCOPY:DAT /IT /ETA /NFL /NDL
[17.08.26 00:38:20][8620] if %errorlevel GE 8 goto ErrorRobocopy
[17.08.26 00:38:20][8620] goto End
[17.08.26 00:38:20][8620] iff "%key" == "c" then
[17.08.26 00:38:20][8620] echo ``
[17.08.26 00:38:20][8620] echo ^e[33;1mATTENTION: Check if all was successfully!^e[0m
[17.08.26 00:38:20][8620] echo ``
[17.08.26 00:38:20][8620] pause
[17.08.26 00:38:22][8620] unset key
[17.08.26 00:38:22][8620] ren /q "c:\ShellConfig\Temp\BAK_Sync_Cloud__State_Runs.txt" "c:\ShellConfig\Temp\BAK_Sync_Cloud__State.txt"
[17.08.26 00:38:22][8620] endlocal
[17.08.26 00:38:22][8620] MapExe /D /N * >& nul
[17.08.26 00:38:22][8620] exit
[17.08.26 00:38:22][8620] history >! "c:\ShellConfig\Logs\TCC_hist-cmd.log"

So, why is that?
 
I have NOT set the "Update Environment on System Change", nevertheless I have the mapexe command also in log, see here for example:

Code:
[17.08.26 00:38:22][8620] endlocal
[17.08.26 00:38:22][8620] MapExe /D /N * >& nul

So, why is that?

That actually makes sense to me. ENDLOCAL restores any variables that were changed within the SETLOCAL/ENDLOCAL block, including (potentially) PATH.
 
Ahh, ok, thank you very much, Charles!
 
That actually makes sense to me. ENDLOCAL restores any variables that were changed within the SETLOCAL/ENDLOCAL block, including (potentially) PATH.
Thank you Charles! I actually just discovered that literally 30 seconds ago, testing a different issue with Logs. I'll post that separately.

So looking at my original issue at the top of this thread, the two executions of MAPEXE might indicate that I was encountering two different ENDLOCAL commands. Interesting. More clues for me to follow.
 
Charles is correct.

In order to allow you to export variables from the ENDLOCAL block, TCC does not simply discard the environment and copy the saved one in its place. It removes every environment variable that you didn't export, and then adds the ones saved by SETLOCAL.

Note: this is very old behavior.

If you're upset by MAPEXE appearing in your logs (which doesn't have anything to do with your issue), you can turn off MAPEXE. (That will make everything else a little slower.)
 
Thanks for the explanation Rex. I know MAPEXE is not the cause of my issue, and I have no concern with MAPEXE in the logs. In fact, it might prove to be useful in figuring out the cause of my intermittent script failures.
 
More info on my issue where my BTM script fails to complete, and mid-script the same BTM script is re-executed from the top, but without the expected command line parameters.

I see that this file "C:\ProgramData\JP Software\Take Command 36\TCC.exception.log" contains the following entries:

Code:
[2026/07/20 05:14:41.225] D:\TakeCommand36\TCConsole\ntinit.cpp:442 wmain()  SEH Exception: 0x00007FF6C850F241 - ACCESS_VIOLATION
[2026/07/25 05:06:05.537] D:\TakeCommand36\TCConsole\ntinit.cpp:442 wmain()  SEH Exception: 0x00007FF6C850F241 - ACCESS_VIOLATION
[2026/08/10 04:15:29.686] D:\TakeCommand36\TCConsole\ntinit.cpp:507 wmain()  SEH Exception: 0x00007FF66A76FD11 - ACCESS_VIOLATION
[2026/08/12 05:10:14.544] D:\TakeCommand36\TCConsole\ntinit.cpp:507 wmain()  SEH Exception: 0x00007FF7A0EBFD11 - ACCESS_VIOLATION
[2026/08/14 05:06:26.138] D:\TakeCommand36\TCConsole\ntinit.cpp:507 wmain()  SEH Exception: 0x00007FF7495EFD21 - ACCESS_VIOLATION
[2026/08/16 10:08:02.531] D:\TakeCommand36\TCConsole\ntinit.cpp:507 wmain()  SEH Exception: 0x00007FF7495EFD21 - ACCESS_VIOLATION
[2026/08/19 05:08:50.619] D:\TakeCommand36\TCConsole\ntinit.cpp:507 wmain()  SEH Exception: 0x00007FF6F811FD21 - ACCESS_VIOLATION

Each one of these SEH exceptions corresponds with the exact dates and times when my script had failures.

Here's the TCCommandLog output from this morning. The second line is where the BackupDaily.btm script was re-executed.

Code:
[ 8/19/26  5:08:50a][14472] if not exist "%sd\%@filename["%extBkupFile"]" DEL /R "%extBkupFile"
[ 8/19/26  5:08:50a][14472] C:\Batfile\BackupDaily.btm
[ 8/19/26  5:08:50a][14472] MapExe /D /N * >& nul
[ 8/19/26  5:08:50a][14472] MapExe /D /N * >& nul
[ 8/19/26  5:08:50a][14472] echo off
[ 8/19/26  5:08:50a][14472] setlocal

Google's AI indicates that this is an access violation crash during TCC startup, and that it could be caused by "a corrupted configuration file, incompatible third-party shell plugins, or aggressive security/antivirus software interfering with memory allocation at startup." Not sure how accurate this info is.

I'm not sure if this is happening when the original execution of the script had some sort of failure, or when the second execution started.

I can see that the output from the second execution is displayed in the same output screen as the original execution. So I don't believe that TCC completely started a brand new session for the second execution, which confuses me as to how this could be a TCC startup issue.
 
The exception location is not in the TCC code (or any of the JP Software-supplied dll's). The reference to line 507 in ntinit.cpp is misleading -- that's the line in the input loop that catches esceptions.

Judging by the address, I would say the most likely source is a third-party injected dll. Try doing a "tasklist /d tcc" and look through the dll list to see if there's any odd ones (not coming from C:\Windows\... or the TCC installation directory).
 
Try doing a "tasklist /d tcc" and look through the dll list to see if there's any odd ones (not coming from C:\Windows\... or the TCC installation directory)

I still had the problem TCC session up from this morning. When I ran the tasklist command there were no .DLLs from anywhere other than C:\Windows and the TCC installation directory.

So I started up a fresh session and ran the same tasklist command and compared the results to the problem session's output.

There differences between the DLLs in the two sessions, but there was only 1 .dll in the new session from a different directory: C:\Program Files\Norton\Suite\aswAMSI.dll The properties for this file confirm that it is part of the Norton 360 suite.

If there was an exception in this .dll, would that cause TCC to restart, and if so would it intentionally restart with the same .BTM on the command line, but without the command line parameters? Or would Windows be in control of what happens in that situation?
 
Also, I figured out that two MAPEXE commands were probably executing because I had inadvertently put two SETLOCAL commands in my script. What seems odd to me is that this would happen, because even though my script appears to have aborted running before reaching the end, it appears that TCC somehow knew that the script had ended and that it should run the [implied?] ENDLOCAL processing twice. Maybe that's expected behavior when an exception is thrown.
 
If there was an exception in this .dll, would that cause TCC to restart, and if so would it intentionally restart with the same .BTM on the command line, but without the command line parameters? Or would Windows be in control of what happens in that situation?

TCC is catching the exception, cleaning up as best it can, and continuing with the next command. It does not restart.

If Windows handles the exception, you'll get a dialog asking if you want to exit or restart the app.
 
Also, I figured out that two MAPEXE commands were probably executing because I had inadvertently put two SETLOCAL commands in my script. What seems odd to me is that this would happen, because even though my script appears to have aborted running before reaching the end, it appears that TCC somehow knew that the script had ended and that it should run the [implied?] ENDLOCAL processing twice. Maybe that's expected behavior when an exception is thrown.

That's WAD.
 
If Windows handles the exception, you'll get a dialog asking if you want to exit or restart the app.
I definitely did not get a dialog from Windows.

TCC is catching the exception, cleaning up as best it can, and continuing with the next command. It does not restart.

What exactly does "continuing with the next command" mean in this context.

1. A .btm script was started from Windows Task Scheduler with a command line equivalent to this:
Code:
"C:\Program Files\JPSoft\TCMD36\tcc.exe" /k C:\Batfile\BackupDaily.btm /B /L /O

2. BTM execution runs from the top until it encounters a "GOSUB Subroutine 1" and transfers control there

3. Within Subroutine 1, there is a "GOSUB Subroutine2" command

4. While executing Subroutine2, an exception was thrown from a third-party injected .dll and TCC catches the exception and logs it in "C:\ProgramData\JP Software\Take Command 36\TCC.exception.log"

In the TCCommandLog it appears that when that happened, TCC then executed the relevant ENDLOCAL commands and then restarted execution of the C:\Batfile\BackupDaily.btm from the start, but without any command line parameters. Is that the expected behavior?

Since the cause of the exception was unknown (was it the last command that caused the issue, or something else?) I'm not sure if there is a perfect response to this series of events. I'm just trying to figure out what exactly is happening so that I can consider how my script should respond while I wait for Norton to fix their 360 Product so it doesn't throw exceptions.
 
Back
Top