控制台问题(100分)

  • 主题发起人 主题发起人 BeginDelphi
  • 开始时间 开始时间
B

BeginDelphi

Unregistered / Unconfirmed
GUEST, unregistred user!
我用ShellExecute or CreateProcess运行一个控制台程序,
怎么知道他运行完没有呢?(我不想用WaitForSingleObject,我的程序没相应了)。

还有,能不能实时的得到他的输出,我用了“管道”,但不能!
 
//Start a DOS program from Delphi 1 and wait for it to finish
//The following Delphi1 procedure executes a DOS program and waits until it finished. Parameter HWindow is the window handle of the calling application, typically you would pass Application.MainForm.Handle there.

//The key function is GetModuleUsage to determine whether the DOS module is still in memory - this function is not available in in Delphi 2/3.

//执行一个dos程序并等待他结束
procedure ExecAndWait(HWindow:HWnd; ExecStr: PChar; CmdShow: word);
var
M : TMsg;
Erg : word;
ErgStr,
MsgStr : array[0..128] of char;
begin
Erg:=WinExec(ExecStr,CmdShow);
if Erg < 32 then
begin
str(erg, ergstr);
strcopy(msgstr,'Could not execute program. Error #: ');
strcat (msgstr, ergstr);
MessageBox(hwindow, ergstr, execstr, mb_ok or mb_iconstop);
end
else
begin { exec waits! }
ShowWindow(hwindow, sw_hide);
repeat
while PeekMessage(m,0,0,0,pm_remove) do
begin
if m.Message=wm_quit then
begin
PostQuitMessage(m.wparam);
exit;
end
else
begin
translatemessage(m);
dispatchmessage(m);
end;
end;
until GetModuleUsage(erg)=0;
ShowWindow(hwindow, sw_shownormal);
end;
end;
 
The key function is GetModuleUsage to determine whether the DOS module is still in memory - this function is not available in in Delphi 2/3.
DElphi 1?什么时候的文章了?
 
老外的文章(很老了),你是要还是不要?
 
接受答案了.
 
后退
顶部