home *** CD-ROM | disk | FTP | other *** search
/ POINT Software Programming / PPROG1.ISO / basic / bmag / shellfix.bas < prev    next >
Encoding:
BASIC Source File  |  1994-05-01  |  2.6 KB  |  63 lines

  1. '─ Area: F-QUICKBASIC ─────────────────────────────────────────────────────────
  2. '  Msg#: 432                                          Date: 27 Apr 94  10:10:24
  3. '  From: Harry F. Harrison                            Read: Yes    Replied: No 
  4. '    To: Corey Seliger                                Mark:                     
  5. '  Subj: Shell?
  6. '──────────────────────────────────────────────────────────────────────────────
  7. ' >         Ok, Interrupt 21h, 4B00h loads & executes programs, but I
  8. ' > don't
  9. ' > know how to incorporate it into my program. I would use SHELL, but I
  10. ' > want
  11. ' > the ERRORLEVEL returned from the child program. What stumps me is the
  12.  
  13. 'EXEC.BAS
  14. 'Won't run in the environment, and only links in when linking stand-alone.
  15. 'If you are compiling with QB or PDS near strings, then change SSEG/SADD to
  16. 'VARSEG/VARPTR.
  17.  
  18. DECLARE FUNCTION Execute% (Program$, Parameter$, DebugFlag%)
  19. '$INCLUDE: '..\include\qbx.bi'
  20. DECLARE SUB FixShell ALIAS "B$ShellRecover" ()
  21. DECLARE SUB SetShell ALIAS "B$ShellSetup" ()
  22.  
  23. STATIC FUNCTION Execute% (Program$, Parameter$, DebugFlag%)
  24.  
  25.     STATIC Regs AS RegTypeX
  26.     DIM Block AS STRING * 14         'this is the DOS parameter block
  27.     DIM Parm AS STRING * 63          'and this is the actual parameter text
  28.     DIM zbuffer$
  29.     DIM dummy&
  30.     DIM exec%
  31.     DIM file
  32.  
  33.     zbuffer$ = Program$ + CHR$(0)      'make an ASCIIZ string for DOS
  34.  
  35.     LSET Parm$ = CHR$(LEN(Parameter$)) + Parameter$ + CHR$(13)
  36.     LSET Block = CHR$(0) + CHR$(0) + MKI$(VARPTR(Parm$)) + MKI$(VARSEG(Parm$))
  37.  
  38.     Regs.AX = &H4B00                 'DOS load/execute function
  39.     Regs.DX = SADD(zbuffer$)          'offset of program name into DX
  40.     Regs.DS = SSEG(zbuffer$)         'set DS to BASIC's segment
  41.     Regs.ES = VARSEG(Block)         'segment of parameter block into ES
  42.     Regs.BX = VARPTR(Block)         'offset of parameter block into BX
  43.  
  44.     CALL SetShell                   '| Unhook interrupts and
  45.     dummy& = SETMEM(-655360)          'set aside memory for C routines.
  46.  
  47.     CALL InterruptX(&H21, Regs, Regs) 'execute it as subordinate process
  48.  
  49.     CALL FixShell                   '| Rehook interrupts and
  50.     dummy& = SETMEM(655360)         '|  reclaim far heap.
  51.  
  52.  
  53.     IF Regs.Flags AND 1 THEN         'DOS had an error trying to run      
  54. exec% = -Regs.AX            'set function value to exit code
  55.     ELSE
  56.         Regs.AX = &H4D00                 'retrieve subordinate process code
  57.         CALL InterruptX(&H21, Regs, Regs)
  58.         exec% = Regs.AX               'set function value to exit code
  59.     END IF
  60.     Execute% = exec%
  61.  
  62. END FUNCTION
  63.