Inconsistent return code for TCC scripts

Aug 23, 2010
637
9
An EXTREMELY simple test case. The reproduction restriction is to start a new CMD session and call pre-created batch file.
Code:
Microsoft Windows [Version 6.1.7601]
(c) Корпорация Майкрософт (Microsoft Corp.), 2009. Все права защищены.

$ stc.btm & echo Finish %ERRORLEVEL%
TYPE "%~0"
VER
QUIT 3

TCC LE  14.00.9 x64   Windows 7 [Version 6.1.7601]
Finish 0

$ stc.btm & echo Finish %ERRORLEVEL%
TYPE "%~0"
VER
QUIT 3

TCC LE  14.00.9 x64   Windows 7 [Version 6.1.7601]
Finish 3

$
Code:
Microsoft Windows [Version 6.1.7601]
(c) Корпорация Майкрософт (Microsoft Corp.), 2009. Все права защищены.

$ C:\Programs\TCC-RT\tcc.exe /C stc.btm & echo Finish %ERRORLEVEL%
TYPE "%~0"
VER
QUIT 3

TCC RT  21.00.24 x64   Windows 7 [Version 6.1.7601]
Finish 0

$ C:\Programs\TCC-RT\tcc.exe /C stc.btm & echo Finish %ERRORLEVEL%
TYPE "%~0"
VER
QUIT 3

TCC RT  21.00.24 x64   Windows 7 [Version 6.1.7601]
Finish 3

$
 
Aug 23, 2010
637
9
I've tested without TCEXIT script. Even if it exists, how could it change the results of the first run and not the next?
 

rconn

Administrator
Staff member
May 14, 2008
12,356
150
I've tested without TCEXIT script. Even if it exists, how could it change the results of the first run and not the next?

If you have conditional operators (as is common in tcstart and tcexit).

There isn't any code in TCC that could return different results in the first run and the next.

Anyone else able to reproduce this?
 
Aug 23, 2010
637
9
I think I'm able to explain it. And it is not your fault.
%ERRORLEVEL% being expanded before the batch file is run, thus only on next invocation it receives the actual return code.
The hint is in SETLOCAL help page, see "delayed explansion" section.
Invoking cmd /V:ON and calling the test as
Code:
stc.btm & echo Result !ERRORLEVEL!
solves the issue.
Note to self: never use compound character in CMD ever again.
 
Similar threads
Thread starter Title Forum Replies Date
vefatica WAD TCC: inconsistent character handling Support 11
T unqlite binary read test is inconsistent Support 2
A Inconsistent @WINPOS // ACTIVATE /POS= behavior Support 0
A Inconsistent treatment of strings with backtiks Support 1
S MSGBOX - inconsistent behavior Support 1
M Somewhat inconsistent limitations… Support 4
vefatica Is EOF an implied RETURN? Support 3
Joe Caverly Why does TCCRT return VIEW as an internal command? Support 6
D Can the argument to RETURN be a function expansion? Support 3
J How to? Speedup of gosub/return Support 8
vefatica Can a subroutine return a 64-bit integer? Support 4
S Return of FTP copy bug in 16.02.48 Support 12
M How to? Get the return code from an external program... Support 8
A WAD function return values with parentheses prevent evaluation of additional functions Support 31
Stefano Piccardi How to? return values from @python Support 2
A How to? return to completion mask after auto-completion Support 14
ehab aboudaya How to? 2 GUI questions and return HWND using TakeCommandIPC Support 3
M echo %@index[1234,.,-1] return -21 in new version Support 3
Jay Sage Function to Return Selected Text Support 2
rconn Do NOT request return receipt! Support 7
rconn No return receipt!! Support 10
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
D What is wrong with this code? Support 7
D v20 code page behavior changes Support 2
vefatica Code page? Support 1
vefatica Exit code of a batch file? Support 4
rconn News Take Command code signing certificate Support 0
Phileosophos Documentation TPIPE /string type code confusion Support 4
M What am I doing wrong in this (very simple!) code? Support 3
M Why does this code produce these results? Support 2
M Why is the exit code zero? Support 6
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

Similar threads