Nathan Campos
Nathan Campos

Reputation: 29507

Output Of a Process

I'm developing a program using Lazarus, that execute gcc:

var
AProcess: TProcess;

begin
if SaveDialog1.Execute then
AProcess := TProcess.Create(nil);
AProcess.CommandLine := 'gcc.exe ' + SaveDialog1.FileName + ' -o ' TextField23.Text;
AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
AProcess.Execute;
AProcess.Free;
end;

But I want to display the log(output) of gcc on another Form(OutputForm), that have only a TMemo(OutputMemo).

How can I do it?

Upvotes: 0

Views: 1558

Answers (1)

RRUZ
RRUZ

Reputation: 136451

you can use the Output property from the TProcess object.

try this code

var
  AProcess: TProcess;
begin
  if SaveDialog1.Execute then begin
    AProcess := TProcess.Create(nil);
    try
      AProcess.CommandLine := 'gcc.exe ' + SaveDialog1.FileName + ' -o '
        + TextField23.Text;
      AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
      AProcess.Execute;

      OutputForm.OutputMemo.Lines.BeginUpdate;
      //OutputForm.OutputMemo.Lines.Clear;
      OutputForm.OutputMemo.Lines.LoadFromStream(AProcess.Output);
      OutputForm.OutputMemo.Lines.EndUpdate;
    finally
      AProcess.Free;
    end;
  end;
end;

Upvotes: 2

Related Questions