Image Map Image Map
Page 1 of 4 1234 LastLast
Results 1 to 10 of 40

Thread: Errorlevels Codes in the DOS Batch process

  1. #1
    Join Date
    Sep 2008
    Location
    Walled Lake, MI
    Posts
    2,809
    Blog Entries
    6

    Default Errorlevels Codes in the DOS Batch process

    I resurrected my old DOS batch menu program (compliments: Van Wolvernton "Supercharging DOS (c) 1986) with the intention of updating it a little bit. Basically what it does is let you gallivant around your PC via a batch file which holds a nice little menu. For example, If I wanted to quit the menu program and return to DOS, I would press the F10 key to exit.

    :GET_RPLY
    reply
    if errorlevel 68 goto F10
    :F10
    cls
    goto END
    :END


    The errolevels for the menu program are 59 through 69 which denotes F1 to F10 with errorlevel 69 sending it back to :Get_RPLY. The input is held by a small program called reply.com, which may be easily assembled through DEBUG. My problem is that I wish to to expand the menu to use F11 and F12 keys. Neither of those two function keys trap as you would expect. My question is does anyone know how to get an errorlevel return from the F11 and F12 keys.
    Last edited by Agent Orange; February 16th, 2013 at 10:05 PM.

  2. #2

    Default

    F11 should be 0x85 and F12 0x86... which works out to 133 and 134 decimal... Reply just returns the scancodes, so errorlevel 133 should get you F11.


    I like the list in the Free Pascal docs because it resembles the one from the back of all the old Turbo manuals I must have photocopied several dozen times the past two and a half or so decades. It's in Hex, but that's easy enough to convert.

    http://www.freepascal.org/docs-html/...dscancode.html

    You might also want to read the microsoft page about it since it includes how to handle multi-key and advanced scancodes.

    http://support.microsoft.com/kb/77457
    From time to time the accessibility of a website must be refreshed with the blood of owners and designers. It is its natural manure.
    CUTCODEDOWN.COM

  3. #3
    Join Date
    Sep 2008
    Location
    Walled Lake, MI
    Posts
    2,809
    Blog Entries
    6

    Default

    Quote Originally Posted by deathshadow View Post
    F11 should be 0x85 and F12 0x86... which works out to 133 and 134 decimal... Reply just returns the scancodes, so errorlevel 133 should get you F11.


    I like the list in the Free Pascal docs because it resembles the one from the back of all the old Turbo manuals I must have photocopied several dozen times the past two and a half or so decades. It's in Hex, but that's easy enough to convert.

    http://www.freepascal.org/docs-html/...dscancode.html

    You might also want to read the microsoft page about it since it includes how to handle multi-key and advanced scancodes.

    http://support.microsoft.com/kb/77457
    Thanks for the reply but I think there may be some confusion between scan codes and batch errrolevels. I'm going to try and bone up the subject through the MS knowledge base.

  4. #4
    Join Date
    Dec 2005
    Location
    Toronto ON Canada
    Posts
    6,650

    Default

    Quote Originally Posted by Agent Orange View Post
    Thanks for the reply but I think there may be some confusion between scan codes and batch errrolevels. I'm going to try and bone up the subject through the MS knowledge base.
    Try COMMAND /Z

    AFAIK DOS only provides 255 errorlevel return codes and I'm not sure if that includes F11 and F12, but worth a try.

  5. #5
    Join Date
    May 2006
    Location
    Melbourne, Australia
    Posts
    5,387

    Default

    Your REPLY program is similar to the GETCH program described at http://www.woodmann.com/RCE-CD-SITES...ttos/batch.htm
    Basically, the program puts a unique number, dependent on the key pressed, into the AL register. ERRORLEVEL uses the contents of the AL register.

  6. #6
    Join Date
    Sep 2008
    Location
    Walled Lake, MI
    Posts
    2,809
    Blog Entries
    6

    Default

    Quote Originally Posted by MikeS View Post
    Try COMMAND /Z

    AFAIK DOS only provides 255 errorlevel return codes and I'm not sure if that includes F11 and F12, but worth a try.
    Can you give me an example?

  7. #7
    Join Date
    May 2006
    Location
    Melbourne, Australia
    Posts
    5,387

    Default

    In your REPLY program, note how errorlevel 68 corresponds to the F10 key. 68 decimal is 44 hex.

    Below is a partial table of key scan codes. The XT code for the F10 key is 44 hex.
    So your REPLY program appears to be putting the XT scan code into the AL register for use by 'errorlevel' functionality.

    If that is the case, it follows that the errorlevel to use for the F11 key is 87, and for the F12 key is 88.


  8. #8

    Default

    Quote Originally Posted by Agent Orange View Post
    Thanks for the reply but I think there may be some confusion between scan codes and batch errrolevels. I'm going to try and bone up the subject through the MS knowledge base.
    If you check the article I linked to, and it's corresponding ASM -- it pulls using the same DOS routine programs like turbo pascal does with it's readkey -- INT 21 function 08 -- input from console without echo. The first number should actually be ASCII 7 bit, if it is zero then it's an extended scancode, throws that value away and then returns -- the extended scancode. UNFORTUNATELY this means that extended codes are reported as other characters, which can be... problematic. (be better if it could store two values somehow). Look at the ASM:

    Code:
    xxxx:0100   MOV AH,08   Get character input without echo
    xxxx:0102   INT 21      Perform MS-DOS service
    xxxx:0104   CMP AL,0    Compare AL with zero
    xxxx:0106   JNZ 010A    If lead zero, get second code of character
    xxxx:0108   INT 21      Perform MS-DOS service
    xxxx:010A   MOV AH,4C   Terminate process with return code
    xxxx:010C   INT 21      Perform MS-DOS service
    Honestly, I'd consider gutting that down to:

    Code:
    MOV AH,08
    INT 21
    MOV AH,4C
    INT 21
    Because it's int21 AH08, it will wait for the keyboard to have something, so a 'successful' result of 0 would actually mean there's an extended keycode waiting.

    :ask
    reply
    if errorLevel 0 goto extendedCodes
    REM process normal scancodes here
    goto ask
    :extendedCodes
    REM process extended scancodes here
    goto ask

    The two "goto ask" being for when it drops through unhandled.

    And again, because it's Int 21 AH 08, what it will give you is IDENTICAL to what turbo pascals readkey would... a non-extended code being the actual ASCII that's currently typed, the extended code being for non-standard keys that don't map to ASCII.

    Which is why the table I linked to on the FPC website is the correct one. That you are getting 59...68 for F1 through F10 -- 3B through 44 hex, bears this out. Check it. It's also why using their reply.com typing any of these ":;<=>?@ABCD" will respond as F1 through F10 -- because theirs doesn't pass the 0 as the marker for an extended scancode.

    I mean, the source code to implement readkey in Turbo Pascal for DOS is just:
    Code:
    function readkey:char; assembler;
    asm
    	mov ah,$08
    	int $21
    end;
    -- edit --
    Oh, and the above has a flaw, you'd want to store the errorlevel since "if errorlevel" will in fact act as true for any value equal to or higher than the value you check against.... major pain in the ass in some cases. If errorLevel 0 would always be true; if errorlevel 68 is true for 69, 70, etc, etc...

    -- edit edit --

    Found it, this guys article explains that better:
    http://www.robvanderwoude.com/errorlevel.php
    Last edited by deathshadow; February 16th, 2013 at 11:57 PM.
    From time to time the accessibility of a website must be refreshed with the blood of owners and designers. It is its natural manure.
    CUTCODEDOWN.COM

  9. #9
    Join Date
    Dec 2005
    Location
    Toronto ON Canada
    Posts
    6,650

    Default

    Quote Originally Posted by Agent Orange View Post
    Can you give me an example?
    If a command terminates with an errorlevel it will be displayed; unfortunately it looks like it only works in DOS 7 (i.e. Win 9x)

  10. #10

    Default

    Taking the errorlevel quirks into account, using the 'gutted' reply.com code I posted above that does not discard 0, this would trap F1 through F12, AND ESC -- without mistaking other keys for the function keys.

    Code:
    :ask
    reply
    if errorlevel 28 goto ask
    if errorlevel 27 goto end
    if errorlevel 1 goto ask
    reply
    if errorlevel 135 goto ask
    if errorlevel 134 goto F12
    if errorlevel 133 goto F11
    if errorlevel 69 goto ask
    if errorlevel 68 goto F10
    if errorlevel 67 goto F9
    if errorlevel 66 goto F8
    if errorlevel 65 goto F7
    if errorlevel 64 goto F6
    if errorlevel 63 goto F5
    if errorlevel 62 goto F4
    if errorlevel 61 goto F3
    if errorlevel 60 goto F2
    if errorlevel 59 goto F1
    goto ask
    From time to time the accessibility of a website must be refreshed with the blood of owners and designers. It is its natural manure.
    CUTCODEDOWN.COM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •