Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide Console When Executing a TProcess

I'm building a application that uses a TProcess called AProcess like this:

procedure TFormMain.btCompileClick(Sender: TObject);
begin
  AProcess := TProcess.Create(nil);
  try
    AProcess.CommandLine := 'gcc.exe "' + OpenDialog1.FileName + '"'
      + ' -o "' + OpenDialog2.FileName + '"';
    AProcess.Options := AProcess.Options + [poWaitOnExit, poUsePipes];
    AProcess.Execute;
    OutputMemo.Lines.BeginUpdate;
    OutputMemo.Lines.Clear;
    OutputMemo.Lines.LoadFromStream(AProcess.Output);
    OutputMemo.Lines.EndUpdate;
  finally
    AProcess.Free;
  end;
end;

But when I click on the button, I got a console window for some seconds and then it exits and all the output of the process is shown on OutputMemo, but I've putted the TMemo because I don't want the console screen. Then I want to know how I can hide this console screen.

like image 932
Nathan Campos Avatar asked Nov 19 '25 09:11

Nathan Campos


1 Answers

I assume you're referring to the TProcess component that comes with Lazarus. To make a console program start without a console, include the poNoConsole flag in the Options property.

AProcess.Options := AProcess.Options + [poNoConsole];

The options available in that property map very closely to the process creation flags for the CreateProcess API function, where the flag to use is CREATE_NO_WINDOW.

like image 100
Rob Kennedy Avatar answered Nov 22 '25 04:11

Rob Kennedy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!