home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / turbo55 / tp55 / execdemo.pas < prev    next >
Pascal/Delphi Source File  |  1989-05-02  |  932b  |  41 lines

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