batch file ending early

Oct 18, 2008
339
2
I am expanding over 100 rar archive file so I have a batch file to call rar.exe for each files to expand. As it turns out about half way processing the files one of the rar file failed the checksum processing that rar performs — rar issue a rc of 3, and seems to end the bat file but there are more files to unrar — is there a signal that rar could be generating to cause the bat file to break? Thanks
 
May 20, 2008
11,400
99
Syracuse, NY, USA
I wonder if WINRAR generates some sort of signal (CTRL_C_EVENT?). Try putting "on break echos > nul" at the beginning of your BTM file.
 
May 30, 2008
235
2
I had a similar problem, but for ROBOCOPY instead of RAR.

I called ROBOCOPY via an environment variable like:

%robocopyvar_with_params%

This sometimes caused the batch file to just stop prematurely.

Problems went away when I replaced that line with:

echo %@exec[%robocopyvar_with_params%]

Could save the exec result to another variable instead of echo:ing it I guess, but this worked for me.

Like your batch file mine also have a gosub containing the via variable execution and that was called many times.
 
Oct 18, 2008
339
2
I had a similar problem, but for ROBOCOPY instead of RAR.

I called ROBOCOPY via an environment variable like:

%robocopyvar_with_params%

This sometimes caused the batch file to just stop prematurely.

Problems went away when I replaced that line with:

echo %@exec[%robocopyvar_with_params%]

Could save the exec result to another variable instead of echo:ing it I guess, but this worked for me.

Like your batch file mine also have a gosub containing the via variable execution and that was called many times.

Hello --- Thanks for the tip ---
 
Oct 18, 2008
339
2
There is one case where TCC will terminate the batch file (and potentially itself). If an external application returns a 3 for the result, TCC will terminate.

Like most seemingly goofy behavior, this is for compatibility with CMD.
There is one case where TCC will terminate the batch file (and potentially itself). If an external application returns a 3 for the result, TCC will terminate.

Like most seemingly goofy behavior, this is for compatibility with CMD.

wow -- yes its goofy -- is there a global/local setting to not comply with the goofy que
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,461
88
Albuquerque, NM
prospero.unm.edu
There is one case where TCC will terminate the batch file (and potentially itself). If an external application returns a 3 for the result, TCC will terminate.
Like most seemingly goofy behavior, this is for compatibility with CMD.
Is there a way to override this goofy CMD compatibility behavior?
 
May 20, 2008
11,400
99
Syracuse, NY, USA
There is one case where TCC will terminate the batch file (and potentially itself). If an external application returns a 3 for the result, TCC will terminate.

Like most seemingly goofy behavior, this is for compatibility with CMD.
Would you explain further?

I just built this.

Code:
INT wmain (INT argc, LPWSTR *argv)
{
    return 3;
}

and ran it from command line/BAT/BTM in TCC and CMD. Nothing odd happened.

Code:
p:\hello\x64\release> type 3.bat
@echo off
p:\hello\x64\release\hello.exe
echo hello.exe returned %errorlevel%
echo I'm still going!
pause

p:\hello\x64\release> cmd
Microsoft Windows [Version 10.0.18363.719]
(c) 2019 Microsoft Corporation. All rights reserved.

P:\Hello\x64\Release> 3.bat
hello.exe returned 3
I'm still going!
Press any key to continue . . .

P:\Hello\x64\Release>
 
Jul 29, 2016
49
1
Would you explain further?

I just built this.

Code:
INT wmain (INT argc, LPWSTR *argv)
{
    return 3;
}

and ran it from command line/BAT/BTM in TCC and CMD. Nothing odd happened.

Code:
p:\hello\x64\release> type 3.bat
@echo off
p:\hello\x64\release\hello.exe
echo hello.exe returned %errorlevel%
echo I'm still going!
pause

p:\hello\x64\release> cmd
Microsoft Windows [Version 10.0.18363.719]
(c) 2019 Microsoft Corporation. All rights reserved.

P:\Hello\x64\Release> 3.bat
hello.exe returned 3
I'm still going!
Press any key to continue . . .

P:\Hello\x64\Release>

Same thing here.....

Code:
D:\Users\Mark\Documents\test 4>type zzz.bat
@echo off
cmd /k "exit 3"
echo Return code was %?
echo Return code was also %errorlevel%
echo %0 is still alive!!!

D:\Users\Mark\Documents\test 4>

Under TCC:

Code:
D:\Users\Mark\Documents\test 4>zzz
Return code was 3
Return code was also 3
zzz is still alive!!!

D:\Users\Mark\Documents\test 4>

Under CMD:

Code:
d:\Users\Mark\Documents\test 4>zzz
Return code was ?
Return code was also 3
zzz is still alive!!!

d:\Users\Mark\Documents\test 4>

This is with:

TCC
Code:
D:\Users\Mark\Documents\test 4>ver

TCC  24.02.51 x64   Windows 10 [Version 10.0.18363.476]

D:\Users\Mark\Documents\test 4>

and

CMD
Code:
d:\Users\Mark\Documents\test 4>ver

Microsoft Windows [Version 10.0.18363.476]

d:\Users\Mark\Documents\test 4>



Note that "cmd /k" tells CMD to stay open after running the command, but the command "exit 3" itself tells CMD to exit with an exit code of 3.
 
May 30, 2008
235
2
@evensenm

I modified your batch file a little:

Code:
@echo off

gosub test %1
gosub test %1

quit

:test [rc]
cmd /k "exit %rc%"
echo Return code was %?
echo Return code was also %errorlevel%
echo %0 is still alive!!!
return

Running it:

Code:
C:\user\test>zzzz 1
Return code was 1
Return code was also 1
zzzz is still alive!!!
Return code was 1
Return code was also 1
zzzz is still alive!!!

C:\user\test>zzzz 3
Return code was 3
Return code was also 3
zzzz is still alive!!!

C:\user\test>zzzz 4
Return code was 4
Return code was also 4
zzzz is still alive!!!
Return code was 4
Return code was also 4
zzzz is still alive!!!

I am using:

TCC 20.11.46 x64 Windows 10 [Version 6.3.16299]
 
Aug 23, 2010
637
9
Can still reproduce it with TCC-RT 25. >.< Weird.
It's even MORE weird since it crashes even parent TCC process.
Any external program that return with code 3 will crash entire TCC stack when used right before "RETURN" statement, even if there's a number of internal commands called in between. Calling any other external command that return with a different exit code before "RETURN" (I've used cygwin's `sleep` utility to have a few seconds to look at the process tree before it all dies) will suppress the effect.
Test setup TCC crash on return from subroutine call
 
Aug 23, 2010
637
9
Workaround is to use CMD style call.
Code:
@ECHO OFF

CALL :test %~1
ECHO %~1:Ok

EXIT /B

:test
"%SystemRoot%\System32\cmd" /S /K "EXIT %~1"
GOTO :EOF
 
Similar threads
Thread starter Title Forum Replies Date
vefatica `Back quotes` - command line vs. batch file Support 5
fpefpe How to? batch file size Support 2
FreezerBurnt Help making a CMD and TCC compatible batch file Support 7
Joe Caverly Set a batch variable (%1 - %n) when TCC is executing a batch file Support 5
P Kill all other instances of tcc from a btm batch file Support 2
K robocopy cancelling batch file processing Support 28
A Unable to pass batch file arguments unaltered Support 18
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
cxxl Set encoding for batch file Support 4
dcantor How to? Batch file to be executed by TCSTART Support 4
D Alias in batch file Support 3
TT's Help! Uninstalling TCC did not restore cmd.exe as Win10 default batch file processor. Support 4
vefatica Exit code of a batch file? Support 4
J cd command altered in batch file Support 3
MickeyF running a program from cmdline versus in batch file Support 1
B Batch file won't run if there is already an instance of TC 17 running Support 9
nickles Fixed Executing long command lines in a batch generates file name errors Support 16
C How to? run a batch file in administrator mode while debugging in take command software Support 1
cgunhouse Fixed bdebugger with not exist batch file causes a crash Support 2
Mezlo menu batch file questions Support 25
F Minimising the command window running from a batch file Support 19
S How to? Batch file problem Support 67
S How to? Incorporate tables from HELP into batch file Support 15
S Fixed TC crashes with a certain batch file Support 6
R How to? debug a nested batch file Support 2
M How to? Save the session log from a batch file? Support 5
S Documentation Topic: Batch File Parameters Support 14
M How to? A very simple question re. the current line number in a batch file... Support 2
Stefano Piccardi IDE unexpectedly exits inside this batch file Support 17
epement Strawberry Perl batch file errors Support 15
B Bdebugger doesn't recognize breakpoint after batch file returns Support 2
E Batch file pauses for no reason Support 16
B Start and keystack do not work in batch file Support 1
B Bdebugger / IDE editor doesn't display called batch file Support 1
M Running a batch file at Windows startup... Support 8
nikbackm Alias - launch external program - batch file Support 16
nickles Using backticks in a batch file Support 8
MBaas GUI-Tool for "File/Open" or tree (for use in batch-files) Support 3
jcalcote Apache Maven startup batch file issues Support 3
deleyd command that launches batch file running TCMD? Support 6
S LOG within a batch file Support 1
vefatica Batch file acts strangely Support 0
D Some feedback on simple batch file Support 2
p.f.moore Equivalent of PRE_EXEC/POST_EXEC in a batch file Support 2
p.f.moore Running another batch file without CALL Support 7
H Configuring the location of BATCH.BCP in the INI file Support 0
fpefpe How to? shortcuts and batch files Support 4
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
R Batch Debugger Command Expansion Window Support 3
K Batch debugger not stepping correctly Support 4

Similar threads