home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / MISC.ZIP / EXECUTE.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1986-01-18  |  2.3 KB  |  65 lines

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