home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / turbo5 / execdemo.pas < prev    next >
Pascal/Delphi Source File  |  1988-10-09  |  914b  |  40 lines

  1. { Copyright (c) 1985, 88 by Borland International, Inc. }
  2.  
  3. program ExecDemo;
  4.  
  5. (*
  6.   Demonstration program that shows how to use the Dos
  7.   unit's Exec procedure to execute DOS commands (including
  8.   running other programs or batch files).
  9.  
  10.   This program keeps prompting you for a DOS command until
  11.   you enter a blank line.
  12.  
  13.   When using Exec, make sure you specify a {$M} directive
  14.   so the heap leaves some memory available for the child
  15.   process.
  16. *)
  17.  
  18. {$M 8192,0,0}           { Leave memory for child process }
  19.  
  20. uses Dos;
  21.  
  22. var
  23.   Command: string[127];
  24.  
  25. begin
  26.   repeat
  27.     Write('Enter DOS command: ');
  28.     ReadLn(Command);
  29.     if Command <> '' then
  30.     begin
  31.       SwapVectors;
  32.       Exec(GetEnv('COMSPEC'), '/C ' + Command);
  33.       SwapVectors;
  34.       if DosError <> 0 then
  35.         WriteLn('Could not execute COMMAND.COM');
  36.       WriteLn;
  37.     end;
  38.   until Command = '';
  39. end.
  40.