Welcome!

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

SignUp Now!

Exit code of a batch file?

May
12,934
170
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:\>
 
This appears to be an obvious CMD bug -- are you saying you want TCC to emulate it?
What's the bug? Under CMD. chain1.cmd returns 1 (the result of "cmd /c exit 1") and chain2.cmd isn't executed.
 
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:\>
 
... or an internal that fails. "DIR *.noexist" does the same thing. CMD thinks the batch file failed and TCC thinks it succeeded.
 

Similar threads

Back
Top