BBS: Inland Empire Archive Date: 02-16-94 (16:03) Number: 155 From: GARY GLUECKERT Refer#: 136 To: FLOYD HOBSON Recvd: NO Subj: Re: Get dos errorlevel Conf: (2) Quik_Bas
FH>check for the errorlevel<G>. There doesn't appear to be a clean way
FH>to do this - my workaroud has been to call the child via a batch file
FH>that creates a nul length semaphore file to reflect the error level,
FH>then delete the nul file after determining the error level.
I found a public domain ASM object file that can be linked into QB4.x,
BASIC 7.x programs which does this so now we can go and do it cleanly
<g>. If you study the code below you will see how it's done and perhaps
you can write the Int calls in BASIC (but why bother if they are in
ASM).
; MonitorShell (MONSHELL.ASM)
; Written by Tony Elliott
; EllTech Development, Inc.
; 4374 Shallowford Industrial Parkway
; Marietta, GA 30066
; (404) 928-8960 Voice or (404) 928-7111 BBS (HST)
; Released into the public domain.
; This routine is written for Microsoft QuickBASIC 4.x, BASIC 6.x and
Microsoft ; PDS 7.x. Assemble using MASM 5.1: MASM MONSHELL;
; You can link it directly to your program, place it in a LINK library
(.LIB) ; or a .QLB.
; To use it:
; DECLARE SUB MonitorShell ()
; DECLARE FUNCTION FetchErrorLevel% ()
;
; CALL MonitorShell
; SHELL "PkZip -Xxy"
; PRINT "ErrorLevel returned from SHELL:";FetchErrorLevel
.model medium, basic
.code
Old21 Label Dword ;Label pointing to old Int 21h handler
Old21Offset dw ? ;Offset part
Old21Segment dw ? ;Segment part
MonitorSet db 0 ;Our "hooked" flag
ExitCode db ? ;Where we store the exit code
MonitorShell proc uses ds
; From BASIC: CALL MonitorShell
cmp cs:MonitorSet,0 ;Are we already hooked?
jnz MonitorExit ;If so, exit
mov ax,3521h ;Get current vector for int 21h
int 21h
mov cs:Old21Segment,es ;Remember it for later
mov cs:Old21Offset,bx
mov ax,2521h
push cs
pop ds ;Point int 21h handler to our code
mov dx, offset OurInt21
int 21h
mov cs:MonitorSet,-1 ;Set our flag
MonitorExit:
ret
OurInt21: ;Our Int 21h handler
cmp ah,4ch ;Is it a 'terminate' request?
jnz Continue ;If not, continue on
mov cs:ExitCode,al ;Remember the exit code
push ax
push ds
mov ax,2521h ;Unhook ourself after the first hit
mov ds,Old21Segment
mov dx,Old21Offset
int 21h ;Point Int 21h back to original handler
pop ds
pop ax
mov cs:MonitorSet,0 ;Set out flag back to zero
Continue:
jmp dword ptr [Old21] ;Transfer control to original Int 21h
MonitorShell endp
FetchErrorLevel proc
;From BASIC: DECLARE FUNCTION FetchErrorLevel%
; PRINT "Last errorlevel:"; FetchErrorLevel%
mov al,cs:ExitCode ;Put the errorlevel into al
xor ah,ah ;Zero ah
ret ;ErrorLevel returned as result
FetchErrorLevel endp
end
If you don't have the MASM compiler to create the .OBJ file you can
FREQ the entire package from 1:107/270 with the magic name MONSHELL,
This goes for all others... help yourself.
Thanks to Tony Elliott for this great little helper!
Gary
$$55
--- QScan v1.06b
* Origin: * Wingit! * Tallahassee, Fl * (904) 386-8693 (1:3605/13)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET