on errorlevel causes btm to mess up TCC

I don't understand what is happening with the following btm file. Without the "on errorlevel" statement, it works fine.

C:\Junk>dir

Volume in drive C is OS Serial number is 1ce5:1203
Directory of C:\Junk\*

3/12/2011 6:04p DIR .
3/12/2011 6:04p DIR ..
3/12/2011 6:03p 256 Foo.btm
3/12/2011 5:54p 745,282 ZippedListDownload1.zip
745,538 bytes in 2 files and 2 dirs 749,568 bytes allocated
146,656,620,544 bytes free

C:\Junk>type Foo.btm
*on errormsg cancel
*on errorlevel ge 1 cancel
*setlocal
*unalias *
echo on

alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ unzip /o /q %1.zip %+ else %+ %=
echo Missing or bad %1 file %+ endiff`

Extract ZippedListDownload1

C:\Junk>Foo.btm
alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ unzip /o /q %1.zip %+ else %+ echo Missing or bad %1 file %+ endiff`
iff %@filesize[ZippedListDownload1.zip] gt 200 then
cancel
C:\Junk>dir

C:\Junk>cd \

C:\Junk>dir

C:\Junk>ver /r

C:\Junk>

At this point, the console ignores whatever I type and just returns a prompt. The result is the same if I run TCC inside TC or standalone.

TCC 12.01.44 Windows Vista [Version 6.0.6002]
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
I don't understand what is happening with the following btm file. Without the "on errorlevel" statement, it works fine.

It doesn't have anything to do with ON ERRORLEVEL; it's the CANCEL inside an IFF statement that's confusing the parser. That's been there forever; I'll look at it but it's a dangerous place to change (lots of opportunity to break backwards compatibility).
 

rconn

Administrator
Staff member
May 14, 2008
12,345
150
Does that mean I shouldn't use CANCEL in ON ERRORMSG or ON ERRORLEVEL if the cancel might happen within an IFF block? Does the same apply to IF? Is QUIT also a problem? Is it OK to put CANCEL or QUIT within an IFF block or in an IF statement?

The problem wasn't simply a CANCEL inside an IFF, it was a CANCEL called by an ON inside an IFF.

12.0.57 (uploaded a couple of hours ago) has a workaround.
 
I installed the new version and now the btm ends normally. But, I don't understand why the ON is firing. First without ON ERRORLEVEL:

Code:
C:\Junk>dir

 Volume in drive C is TI105444W0C    Serial number is 709c:de9d
 Directory of  C:\Junk\*

 3/24/2011  11:19a        DIR    .
 3/24/2011  11:19a        DIR    ..
 3/24/2011  11:19a            275  Foo.btm
 3/22/2011   3:42p        715,367  ZippedListDownload1.zip
           715,642 bytes in 2 files and 2 dirs    720,896 bytes allocated
   249,338,101,760 bytes free

C:\Junk>type Foo.btm
*on errormsg cancel
rem *on errorlevel ge 1 cancel
*setlocal
*unalias *
echo on

alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ echo %? %_? %+ unzip /o /q %1.zip %+ echo %? %_? %+ else %+ %=
echo Missing or bad %1 file %+ endiff`

Extract ZippedListDownload1

C:\Junk>Foo.btm
alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ echo %? %_? %+ unzip /o /q %1.zip %+ echo %? %_? %+ else %+ echo Missing or bad %1 file %+ endiff`
iff %@filesize[ZippedListDownload1.zip] gt 200 then
echo 0 0
0 0
unzip /o /q ZippedListDownload1.zip
echo 0 0
0 0
Now with ON ERRORLEVEL:

Code:
C:\Junk>type Foo.btm
*on errormsg cancel
*on errorlevel ge 1 cancel
*setlocal
*unalias *
echo on

alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ echo %? %_? %+ unzip /o /q %1.zip %+ echo %? %_? %+ else %+ %=
echo Missing or bad %1 file %+ endiff`

Extract ZippedListDownload1

C:\Junk>Foo.btm
alias Extract=`iff %@filesize[%1.zip] gt 200 then %+ echo %? %_? %+ unzip /o /q %1.zip %+ echo %? %_? %+ else %+ echo Missing or bad %1 file %+ endiff`
iff %@filesize[ZippedListDownload1.zip] gt 200 then
cancel

C:\Junk>

Also, the Help for ERRORLEVEL in the first sentence says _? when it means ?.
 
It seems the exit code isn't put in the variables:

Code:
C:\Junk>type Foo.btm
*on errorlevel ge 1 echo on errorlevel %errorlevel %? %_?
iff 300 gt 200 then
   echo greater
else
   echo less
endiff
echo %errorlevel %? %_?

C:\Junk>Foo.btm
on errorlevel 0 0 0
greater
0 0 0

Perhaps I'm missing something, but ON ERRORLEVEL doesn't seem too useful if various internal commands will trigger it, even when they aren't producing an error.
 
Similar threads
Thread starter Title Forum Replies Date
Joe Caverly PSHELL and @PSHELL errorlevel values Support 4
D COPY returns ERRORLEVEL 2 Support 5
C FFIND ERRORLEVEL Support 2
D on errorlevel n only executes when equal Support 1
M ON ERRORLEVEL not being trapped Support 1
vefatica TIMER causes confusion Support 2
M WAD Set statements in () causes problems Support 8
M Fixed Set "VAR=VAL" format causes problems Support 12
H lua Causes Take Command Tab to Exit Support 5
cgunhouse Fixed bdebugger with not exist batch file causes a crash Support 2
vefatica Fixed FOLDERMONITOR causes crash Support 23
D Fixed Removing the mail password causes GPF Support 2
T How to? Using FOLDERMONITOR 1 event causes multiple trigger(ing)s Support 8
B DIR /Z Causes GPF in TCMD V10 B50 Support 5
S PDIR command causes GPF Support 5
williamleara Specifying path to TCMD.INI causes issues Support 8
I shralias causes svchost.exe to use 100% cpu Support 10
B DIR /Z Causes Application Error In At Least One Directory Support 4
A Bug report: unsetarray causes GPF Support 0
A Bug report: unsetarray causes GPF Support 2
MickeyF equivalent to TCSTART.btm for TCMD? Support 4
vefatica Console not redrawn in BTM or with multiple commands Support 4
Joe Caverly Embedding an .EXE (or other file) into a .BTM Support 8
Charles S. Roaten Problems with TCSTART.BTM Support 1
P Kill all other instances of tcc from a btm batch file Support 2
C TCC 26 BATCOMP BTM problems? Support 5
B IF command problem in tcexit.btm Support 9
vefatica WAD DIR.BTM? Support 11
vefatica BTM, elevated, console window caption? Support 4
I BTM slower than BAT? Support 14
D btm file command line augments comparing for string or math. Support 12
D check for network tcstart.btm and load if newer Support 3
Craig Fitzgerald Problems using tcstart.btm Support 3
vefatica Installer sets BTM associations wrongly Support 4
O I cannot use links to .btm files Support 5
CWBillow Can't right-click a BTM Support 7
C NE1 have BTM to remove %appdata\JP Software\ etc... Support 0
C interesting TCStarts.btm Support 2
JohnQSmith ALIAS /R in TCSTART.BTM Support 9
Paul Berwanger BTM Bugs Support 2
M Drag and Drop for .BTM scripts Support 10
D WAD START /ELEVATED "Title" /PGM "job.btm" Support 6
C How to? run a BTM in elevated, inv tcc tab window Support 9
Roedy How to? Understanding BTM file properties Support 0
Fross GetOpt.btm Support 0
Roedy BTM file encoding Support 13
C How to? Add date/time to custom tpipe based BTM Support 1
thedave Problem chaining piped FIND commands in BTM Support 7
P Concatenating strings in a BTM Support 3
C Cmpr_Del.btm need help understanding UDF..... Support 2

Similar threads