here is my code for using TProcess.
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, process, FileUtil, Forms, Controls, Graphics,
Dialogs, StdCtrls;
type
{ TForm1 }
TForm1 = class(TForm)
Button1 : TButton;
Memo1 : TMemo;
pr12 : TProcess;
pr1 : TProcess;
procedure Button1Click(Sender : TObject);
private
{ private declarations }
public
procedure am(const str: string );
{ public declarations }
end;
var
Form1 : TForm1;
implementation
{$R *.lfm}
const
BSIZE = 2048; // Buffer size for reading the output in chunks
{ TForm1 }
procedure TForm1.Button1Click(Sender : TObject);
var
os : TMemoryStream;
BRead : longint;
Buf : array[1..BSIZE] of byte;
ls: TStringList;
I : Integer;
begin
pr12.Execute;
BRead := 0;
os := TMemoryStream.Create;
ls := TStringList.Create;
try
repeat
Application.ProcessMessages;
BRead := 0;
os.clear;
ls.Clear;
BRead := pr12.Output.Read(Buf, BSIZE);
if BRead = 0 then Break;
os.Write(Buf, BRead);
// write to list
os.Position := 0;
ls.LoadFromStream(os);
for I:=0 to Pred(ls.Count) do begin
am(ls.Strings[I]);
Application.ProcessMessages;
end;
Application.ProcessMessages;
Sleep(100);
until BRead = 0;
finally
os.Free;
ls.Free;
end;
// WORKS ... not so good
//while pr12.Running do begin
// Application.ProcessMessages;
// Memo1.Lines.LoadFromStream(pr12.Output);
//end;
end;
procedure TForm1.am(const str : string);
begin
Memo1.Lines.Add(str);
end;
end.
{ }
It works and display the final result of the operation.
But What I want is to show the result of the operation in sychronisation of the running process, something like a prograss on curl command line .
In my example I use upx to compress an EXE file but it shows me the final result and not the pregression of the compression of the file.
So, Any help ??