home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp21beta.zip / OEXMPSRC.RAR / OS2EXEC / TESTEXEC.PAS < prev   
Pascal/Delphi Source File  |  2000-08-15  |  3KB  |  73 lines

  1. {█▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█}
  2. {█                                                       █}
  3. {█      Virtual Pascal Examples. Version 2.1             █}
  4. {█      Redirected execution example                     █}
  5. {█      ─────────────────────────────────────────────────█}
  6. {█      Copyright (C) 1996-2000 vpascal.com              █}
  7. {█                                                       █}
  8. {▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀}
  9.  
  10. Program TestExec;
  11.  
  12. {&PMTYPE VIO}
  13.  
  14. {$Delphi+,T-,X+,Use32-}
  15.  
  16. Uses
  17.   Crt, Os2Exec, Os2Base, SysUtils;
  18.  
  19. // This demonstration of capturing the output of a child
  20. // process runs DIR C:\*.* and displays the result in a window.
  21.  
  22. procedure Directory;
  23. Var
  24.   tr  : TRedirExec;
  25.   i   : Integer;
  26.   x,y : Integer;
  27.  
  28. begin
  29.   Writeln;
  30.   Writeln( 'Executing DIR C:\*.* 5 times, displaying the output in a window' );
  31.   tr := TRedirExec.Create;                   // Create a TRedirExec instance
  32.   if Assigned( tr ) then                     // If creation was ok...
  33.     try                                      // Catch any errors
  34.       TextColor( White );
  35.       For i := 1 to 5 do                     // Run 5 times
  36.         begin
  37.           x := 5+5*i;                        // Set up coordinates of window
  38.           y := 3+2*i;
  39.           TextBackground( i );
  40.           Window( x, y, x+45, y+8 );         // Create Crt window
  41.           ClrScr;                            // Clear it
  42.           TextBackground( Black );
  43.           Window( x+1, y+1, x+44, y+7 );     // Set up "inside" window
  44.           ClrScr;                            // Clear it in black
  45.           { Execute the command to grab the output from }
  46.           tr.Execute( 'CMD.EXE', '/C DIR C:\*.*', nil );
  47.           While not tr.Terminated do         // While command is executing
  48.             If tr.MessageReady then          // Ask if a line is ready
  49.               Writeln( tr.Message )          // - Display it
  50.             else
  51.               DosSleep( 30 );                // - otherwise wait a little
  52.         end;
  53.  
  54.       Window( 1, 1, 80, 25 );                // Restore screen to normal
  55.       TextBackground( Black );
  56.       TextColor( LightGray );
  57.       Gotoxy( 1, 23 );
  58.     finally
  59.       tr.Destroy;                            // Free the instance
  60.     end
  61.   else
  62.     Writeln( 'Error creating TRedirExec class instance' );
  63. end;
  64.  
  65. begin
  66.   ClrScr;
  67.   Writeln( 'Redirected Execute Demo v2.1           (C) 1996-2000 vpascal.com' );
  68.   PopupErrors := False;                      // Tell SysUtils to display
  69.                                              // exceptions on user screen
  70.  
  71.   Directory;                                 // Test the function
  72. end.
  73.