执行 TProcess 时隐藏控制台
我正在构建一个使用名为 AProcess
的 TProcess
的应用程序,如下所示:
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;
但是当我单击按钮时,我会看到一个控制台窗口几秒钟,然后它退出并该过程的所有输出都显示在 OutputMemo
上,但我放置了 TMemo
因为我不需要控制台屏幕。然后我想知道如何隐藏这个控制台屏幕。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您指的是
TProcess
< /a> Lazarus 自带的组件。要使控制台程序在没有控制台的情况下启动,请包含poNoConsole<
Options< 中的 /code>
标志/code> 属性。
该属性中的可用选项与进程创建标志非常接近
CreateProcess
API 函数,其中标志使用的是CREATE_NO_WINDOW
。I assume you're referring to the
TProcess
component that comes with Lazarus. To make a console program start without a console, include thepoNoConsole
flag in theOptions
property.The options available in that property map very closely to the process creation flags for the
CreateProcess
API function, where the flag to use isCREATE_NO_WINDOW
.