1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

on errorlevel causes btm to mess up TCC

Discussion in 'Support' started by David Marcus, Mar 12, 2011.

  1. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    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]
     
  2. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    Still happens with

    TCC 12.10.56 x64 Windows 7 [Version 6.1.7601]

    Is "on errorlevel" broken?
     
  3. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    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).
     
  4. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    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?
     
  5. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    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.
     
  6. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    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 ?.
     
  7. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,860
    Likes Received:
    83
    The ON ERRORLEVEL is executing because the IFF is returning a non-zero value (required in order to allow you to pipe the output of an IFF, and to support the || and && conditional operators).
     
  8. David Marcus

    Joined:
    Jun 4, 2008
    Messages:
    648
    Likes Received:
    1
    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.
     

Share This Page