home *** CD-ROM | disk | FTP | other *** search
- {.F-}
- {
- Executes any DOS or external command from within Turbo Pascal.
- Call as EXECUTE CommandString
- CommandString may be any DOS INTERNAL, Batch, COM or EXE command
- and may include command line arguments.
- Note that the PATH is automatically searched
- for any external program files.
-
- IMPORTANT: Compile with min heap = $200/ max heap = $200.
-
- The procedure execute_string may be incorporated into any Turbo program.
- it is the responsibility of the host program to deallocate sufficient
- memory above itself for the external command to execute.
-
- ************************WARNING*******************************
- * this technique uses undocumented features of MSDOS. *
- * It appears to work on all versions of MSDOS (2.X-3.1), *
- * but since it is undocumented it may not always work. *
- **************************************************************
-
- written by Russ Nelson, Potsdam, NY.
- small modifications and uploaded by Kim Kokkonen, 72457,2131.
- }
- {.F+}
-
- PROGRAM Execute;
- TYPE
- str255 = STRING[255];
- VAR
- commandline : str255 ABSOLUTE CSeg : $80;
-
- PROCEDURE execute_string(s : str255);
- { execute_string -- execute a command line }
- VAR
- save_ax : Integer;
- CONST
- save_ss : Integer = 0;
- save_sp : Integer = 0;
- BEGIN
- s[Length(s)+1] := ^M;
- INLINE(
- $1E/ { push ds }
- $55/ { push bp }
- $2E/$8C/$16/save_ss/ { mov cs:[save_ss],ss }
- $2E/$89/$26/save_sp/ { mov cs:[save_sp],sp }
- $8C/$D0/ { mov ax,ss }
- $8E/$D8/ { mov ds,ax }
- $8D/$76/<s/ { lea si,s[bp] }
- $CD/$2E/ { int 2eh }
- $2E/$8E/$16/save_ss/ { mov ss,cs:[save_ss] }
- $2E/$8B/$26/save_sp/ { mov sp,cs:[save_sp] }
- $5D/ { pop bp }
- $1F/ { pop ds }
- $89/$46/<save_ax { mov save_ax[bp],ax }
- );
- IF save_ax <> 0 THEN WriteLn('Exit code = ', save_ax);
- END;
-
- BEGIN
- IF Length(commandline) > 0
- THEN execute_string(commandline)
- ELSE execute_string('dir/w');
- END.