Welcome!

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

SignUp Now!

on errorlevel causes btm to mess up TCC

Jun
760
6
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]
 
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).
 
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?
 
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

Back
Top