home *** CD-ROM | disk | FTP | other *** search
/ RBBS in a Box Volume 1 #3.1 / RBBSIABOX31.cdr / fasm / execut.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-06-09  |  2.9 KB  |  79 lines

  1. (*[72457,2131]
  2. EXECUT.PAS                18-Jan-86 2385
  3.  
  4.     Keywords: PCDOS MSDOS COMMAND EXECUTE EXTERNAL
  5.  
  6.     This program demonstrates an alternate technique for executing any DOS
  7.     internal, .BAT, .COM or .EXE command from within a Turbo program. It uses
  8.     an "undocumented" MSDOS interrupt to make a reentrant call to COMMAND.COM,
  9.     thus saving memory and making the calling code much smaller and simpler
  10.     than the DOS EXEC function. Has been used and shown to work on DOS 2.0,
  11.     2.1, 3.0 and 3.1.
  12. *)
  13.  
  14. {.F-}
  15. {
  16. Executes any DOS or external command from within Turbo Pascal.
  17. Call as EXECUTE CommandString
  18. CommandString may be any DOS INTERNAL, Batch, COM or EXE command
  19.   and may include command line arguments.
  20. Note that the PATH is automatically searched
  21.   for any external program files.
  22.  
  23. IMPORTANT: Compile with min heap = $200/ max heap = $200.
  24.  
  25. The procedure execute_string may be incorporated into any Turbo program.
  26. it is the responsibility of the host program to deallocate sufficient
  27. memory above itself for the external command to execute.
  28.  
  29. ************************WARNING*******************************
  30. *    this technique uses undocumented features of MSDOS.     *
  31. *    It appears to work on all versions of MSDOS (2.X-3.1),  *
  32. *    but since it is undocumented it may not always work.    *
  33. **************************************************************
  34.  
  35. written by Russ Nelson, Potsdam, NY.
  36. small modifications and uploaded by Kim Kokkonen, 72457,2131.
  37. }
  38. {.F+}
  39.  
  40. PROGRAM Execute;
  41. TYPE
  42.   str255 = STRING[255];
  43. VAR
  44.   commandline : str255 ABSOLUTE CSeg : $80;
  45.  
  46.   PROCEDURE execute_string(s : str255);
  47.     { execute_string -- execute a command line }
  48.   VAR
  49.     save_ax : Integer;
  50.   CONST
  51.     save_ss : Integer = 0;
  52.     save_sp : Integer = 0;
  53.   BEGIN
  54.     s[Length(s)+1] := ^M;
  55.     INLINE(
  56.       $1E/                    {   push    ds                   }
  57.       $55/                    {   push    bp                   }
  58.       $2E/$8C/$16/save_ss/    {   mov     cs:[save_ss],ss      }
  59.       $2E/$89/$26/save_sp/    {   mov     cs:[save_sp],sp      }
  60.       $8C/$D0/                {   mov     ax,ss                }
  61.       $8E/$D8/                {   mov     ds,ax                }
  62.       $8D/$76/<s/             {   lea     si,s[bp]             }
  63.       $CD/$2E/                {   int     2eh                  }
  64.       $2E/$8E/$16/save_ss/    {   mov     ss,cs:[save_ss]      }
  65.       $2E/$8B/$26/save_sp/    {   mov     sp,cs:[save_sp]      }
  66.       $5D/                    {   pop     bp                   }
  67.       $1F/                    {   pop     ds                   }
  68.       $89/$46/<save_ax        {   mov     save_ax[bp],ax       }
  69.       );
  70.     IF save_ax <> 0 THEN WriteLn('Exit code = ', save_ax);
  71.   END;
  72.  
  73. BEGIN
  74.   IF Length(commandline) > 0
  75.   THEN execute_string(commandline)
  76.   ELSE execute_string('dir/w');
  77. END.
  78.  
  79.