home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / PASCAL / PASTUT34 / DOSOPS.PAS < prev    next >
Pascal/Delphi Source File  |  1993-06-17  |  2KB  |  61 lines

  1. program dos_operations;
  2.  
  3. {~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~}
  4. { Program to illustrate the use of DOS operations from a Pascal Program. }
  5. {                                                                        }
  6. { DOSOPS.PAS      R. Shaw    5.4.91                                      }
  7. {                                                                        }
  8. {________________________________________________________________________}
  9.  
  10. {$M $4000,0,0}     {Sets memory allocation - stacksize, heapmin, heapmax}
  11.                    {see page 272 of Programmer's Guide for syntax       }
  12.  
  13. uses DOS, Crt;     {Makes available the procedures and functions of Units}
  14.  
  15. var
  16.    x,y,z         : integer;
  17.    dir,dir2,dir3 : string;
  18.    c             : char;
  19.  
  20. begin
  21.    clrscr;
  22.    {This is a trivial background task into which DOS commands are inserted}
  23.    x := 1;
  24.    y := 3;
  25.    z := 0;
  26.    GetDir(0,dir);       {I/O procedure from System unit - p131 Prog. Guide}
  27.    writeln('Start directory is ',dir);
  28.    writeln('Press any key to continue');
  29.    writeln;
  30.    c := readkey;
  31.    z := x + y;
  32.    ChDir('\');      {I/O procedure from System unit - p131 Prog. Guide}
  33.    GetDir(0,dir2);
  34.    writeln('Changed directory is ',dir2);
  35.    writeln('Press any key to continue and list all *.SYS files');
  36.    writeln;
  37.    c := readkey;
  38.    SwapVectors;         {Process-handling procedure from DOS unit - p146 }
  39.  
  40.    Exec(GetEnv('COMSPEC'),'/C DIR *.SYS');    {Also from DOS unit - pp146/7}
  41.    If DosError <> 0 Then
  42.      Begin
  43.        Writeln('Error loading child program COMMAND.COM');
  44.        writeln('Dos error #', DosError);
  45.        writeln('Please check your operating system files.');
  46.      End;
  47.    SwapVectors;
  48.    writeln;
  49.    ChDir(dir);
  50.    GetDir(0,dir3);
  51.    writeln('Return to start directory, ',dir3);
  52.    writeln('Press any key to continue');
  53.    writeln;
  54.    c := readkey;
  55.    z := z + 3;
  56.    writeln('The background task gives z = x + y + 3 = ',x,' + ',y,' + 3 = ',z);
  57.    writeln('Press any key to continue');
  58.    c := readkey;
  59. end.
  60.  
  61.