<--- Turn the page     (contents page)     Turn the page --->


Undocumented

Getting ERROR LEVEL a different way




This months column I will show you where DOS stores the current ERRORLEVEL value and attribute. Sure you could use function 4Dh of Interrupt 21h, but if you didn't know, this function clears the ERRORLEVEL and so calling function 4Dh again, returns 0000h.

Sure you could get the ERRORLEVEL code and save it somewhere, but what is the fun in that?

DOS stores the ERRORLEVEL code at offset 14h in the "Swappable Data Area" table. You can get this table using service 5D06h of Interrupt 21h. The address of this table is returned in DS:SI.

See Listing 1 to the right.


Listing 1:
           push ds
           mov  ax,5D06h
           int  21h
           add  si,14h
           lodsw
           pop  ds

Service 5Dh, subservice 06h returns the segmented address of this table as DS:SI. Move to offset 14h (si + 14h) and get the word (2 bytes) at this position.

  ; ah = 00 normal voluntary end
  ;    = 01 termination by MS-DOS due to a keyboard break (Ctrl-C)
  ;    = 02 termination by MS-DOS due to a critical error
  ;    = 03 normal voluntary end due to a TSR
  ; al = RC (error level)
See Ralf Browns interrupt list for more on this table. ¥


<--- Turn the page     (contents page)     Turn the page --->

Page 13