'------- EXECUTE.BAS 'Copyright (c) 1992 Crescent Software, Inc. DEFINT A-Z DECLARE FUNCTION Execute% (FullFileName$, Parameter$) TYPE RegType AX AS INTEGER BX AS INTEGER CX AS INTEGER DX AS INTEGER BP AS INTEGER SI AS INTEGER DI AS INTEGER Flags AS INTEGER DS AS INTEGER ES AS INTEGER END TYPE CLS Program$ = "C:\PDS\BC.EXE" CmdLine$ = "MYPROG.BAS /O;" ReturnCode = Execute%(Program$, CmdLine$) LOCATE 7 IF ReturnCode THEN IF ReturnCode < 0 THEN 'a negative value means it was a DOS error PRINT "DOS error during execution: "; ReturnCode ELSE PRINT "The executed program returned a DOS errorlevel of"; ReturnCode END IF ELSE PRINT "Execution successful!" END IF END FUNCTION Execute% (Program$, Parameter$) STATIC '---- Prepare the program name and parameter strings for processing. DOS ' requires that the parameter string hold the length of the parameter ' text, followed by the parameter text, and then followed by a CHR$(13) ' Enter byte. The parameter block holds two CHR$(0) bytes followed by ' the address and segment of the parameter string. ' DIM Block AS STRING * 14 'this is the DOS parameter block DIM Parm AS STRING * 50 'and this is the actual parameter text DIM ZBuffer AS STRING * 80 'this holds a copy of the program name DIM Regs AS RegType 'for CALL Interrupt Zero$ = CHR$(0) 'invoke CHR$() only once for efficiency DOS = &H21 'saves a few bytes ZBuffer$ = Program$ + Zero$ 'make an ASCIIZ string for DOS LSET Parm$ = CHR$(LEN(Parameter$)) + Parameter$ + CHR$(13) LSET Block$ = Zero$ + Zero$ + MKI$(VARPTR(Parm$)) + MKI$(VARSEG(Parm$)) Dummy& = SETMEM(-600000) 'free up memory for the program being run Regs.AX = &H4B00 'DOS load/execute function Regs.DX = VARPTR(ZBuffer$) 'offset of program name into DX Regs.ES = VARSEG(Block$) 'segment of parameter block into ES Regs.BX = VARPTR(Block$) 'offset of parameter block into BX Regs.DS = -1 'set DS to BASIC's segment CALL InterruptX(DOS, Regs, Regs) 'execute it as subordinate process 'CALL InterruptX(DOS, Regs) 'use this with P.D.Q. IF Regs.Flags AND 1 THEN 'DOS error trying to run the program? Execute% = -Regs.AX 'yes, set function value to exit code GOTO Done 'and jump to reclaim memory END IF Regs.AX = &H4D00 'retrieve subordinate process code CALL Interrupt(DOS, Regs, Regs) 'CALL Interrupt(DOS, Regs) 'use this with P.D.Q. Execute% = Regs.AX 'set function value to negative exit code Done: Dummy& = SETMEM(600000) 'reclaim the memory relinquished eariler END FUNCTION