Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

CaptureConsoleOutput

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

CaptureConsoleOutput.pas

Procedure that executes console command and redirects it's output to the callback procedure. Should be used only in an asynchronous context (use TThread or TTask.Run()), beucase of TThread.Synchronize() that is used inside the procedure.

Tested with RAD Studio 11.0 Alexandria on Windows 11 (Version 21H2) and macOS 11.6.1 Big Sur.

Usage

pascal
uses
  CaptureConsoleUnit;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TTask.Run(procedure begin
    CaptureConsoleOutputSync('ping google.com',
      procedure (const Line: String) begin
        Memo1.Lines.Add(Line);
        Memo1.GoToTextEnd;
      end);
  end);
end;