流程的输出

时间:2009-12-28 13:27:22

标签: lazarus delphi

我正在使用Lazarus开发一个程序,执行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;

但是我想在另一个只有TMemo(OutputForm)的Form(OutputMemo)上显示gcc的日志(输出)。

我该怎么做?

1 个答案:

答案 0 :(得分:2)

您可以使用Output对象中的TProcess属性。

试试这段代码

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;