Exit code of a batch file?

May 20, 2008
11,414
99
Syracuse, NY, USA
This is from the LE forum but it is equally appropriate here.

Here are two simple batch files.
Code:
v:\> type chain1.cmd
@echo off
if "%1"=="1" (cmd /c exit 1) else (echo foo)

v:\> type chain2.cmd
@echo off
echo chain2.cmd was executed

Here's the result of conditional execution with CMD.
Code:
V:\> chain1.cmd 1 && chain2.cmd

V:\>

And here's the result with TCC19.
Code:
v:\> chain1.cmd 1 && chain2.cmd
chain2.cmd was executed

v:\>
 
May 20, 2008
11,414
99
Syracuse, NY, USA
Replace "cmd /c exit 1" with any external that fails. Here's another using "net stop stisvc".

CMD doesn't run the second batch file (seems right).
Code:
V:\> chain1.cmd 1 && chain2.cmd
The Windows Image Acquisition (WIA) service is not started.

More help is available by typing NET HELPMSG 3521.

V:\>

And TCC does run the second batch file.
Code:
v:\> chain1.cmd 1 && chain2.cmd
The Windows Image Acquisition (WIA) service is not started.

More help is available by typing NET HELPMSG 3521.

chain2.cmd was executed

v:\>
 
May 20, 2008
11,414
99
Syracuse, NY, USA
... or an internal that fails. "DIR *.noexist" does the same thing. CMD thinks the batch file failed and TCC thinks it succeeded.
 
Similar threads
Thread starter Title Forum Replies Date
M Why is the exit code zero? Support 6
S How to? Runs start /w in invisible mode OR run program after exit of another one Support 3
vefatica ON EXIT? Support 8
P exit /b in batch files Support 7
rps Reboot and exit reason Support 10
H lua Causes Take Command Tab to Exit Support 5
Stefano Piccardi MKLNK exit status Support 9
ed neff How to? exit TCC/Take Command to a new directory Support 10
SeoulBigChris Save Environment (Tabs) on Exit? Support 3
Stefano Piccardi EXIT hangs Support 5
R TC 13 / Using TCDIALOG to exit commands Support 4
M Not real important but kind of annoying EXIT issue... Support 20
lassevk exit(1) in a python script exits console, by design or bug? Support 1
cgunhouse IDE Crashes on Exit Support 6
J tcmd.exe/tcc.exe appcrash on exit Support 4
M Goto fails when a text endtext block precedes the code Support 5
rconn News Update: Code Signing Certificate Status Support 16
Peter Murschall UNICODE mixed with ANSI Code Support 11
A Inconsistent return code for TCC scripts Support 4
D What is wrong with this code? Support 7
D v20 code page behavior changes Support 2
vefatica Code page? Support 1
rconn News Take Command code signing certificate Support 0
Phileosophos Documentation TPIPE /string type code confusion Support 4
M How to? Get the return code from an external program... Support 8
M What am I doing wrong in this (very simple!) code? Support 3
M Why does this code produce these results? Support 2
S WAD _exit returns invalid code under some conditions Support 13
T @ping: response code, data size and documentation incorrect Support 2
C plugin or code to verify email addresses ? Support 7
vefatica Code page? Support 0
B BB code is Off? Support 2
D bug in ftp code Support 19
fpefpe How to? shortcuts and batch files Support 4
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
M Oracle batch OPatch.bat.bat not working in TCC but correctly in CMD Support 5
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
fpefpe batch file ending early Support 18
R Batch Debugger Command Expansion Window Support 3
K robocopy cancelling batch file processing Support 28
A Unable to pass batch file arguments unaltered Support 18
K Batch debugger not stepping correctly Support 4
S incorrect message at start Cancel batch job 4START.bat ? (Y/N/A) : Support 1
MickeyF Why does this batch file give me 'unknown command "else"' error? Support 17
Joe Caverly "Functions" in cmd.exe batch files Support 6
S Batch files Calling Batch Files Support 2
P Labels in batch files: TCC vs CMD.exe Support 9

Similar threads