本文介绍了如何在Delphi控制台应用程序中运行控制台应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的控制台应用程序启动另一个控制台应用程序,显示该另一个应用程序想要显示的所有内容,然后在另一个应用程序完成并退出后执行一些操作。
基本上是:
I want my console application to start another console application, display everything this another application wants to display then do something after this another application finishes and exit.Basically:
Writeln('Started');
ShellExecute(0, 'open', 'another.exe', nil, nil, SW_SHOWNORMAL);
Writeln('Finished');
那么如何在我的控制台应用程序中显示另一个控制台应用程序的所有输出?
我不想捕获其他应用程序的输出。我只希望另一个应用程序在同一命令行窗口中执行。
So how can I show all the output from another console app in my console app?I don't want to capture output from another app. I just want another app to execute in the same command line window.
推荐答案
您可能想尝试这样的事情:
You might want to try something like this:
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
Windows, SysUtils;
var
cl: string;
SI: TStartupInfo;
PI: TProcessInformation;
begin
cl := 'C:\WINDOWS\System32\ping.exe 127.0.0.1';
UniqueString(cl);
try
try
writeln('begin');
FillChar(SI, sizeof(SI), 0);
FillChar(PI, sizeof(PI), 0);
SI.cb := sizeof(SI);
if not CreateProcess(nil, PChar(cl), nil, nil, true, 0, nil, nil, SI, PI) then
RaiseLastOSError;
WaitForSingleObject(PI.hProcess, INFINITE);
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
writeln('end');
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
finally
Writeln('Complete');
Readln;
end;
end.
这篇关于如何在Delphi控制台应用程序中运行控制台应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!