[阅读: 492] 2007-09-27 03:19:18
加断点看了一下,好像读输出时,会停在那里!
FillChar(pBuf^, iBufSize, #0); //empty the buffer
ReadFile(read_stdout, pBuf^, iBufSize, bread, nil); //read the stdout pipe
Str := Last; //take the begin of the line (if exists)
i := 0;
while ((i < bread) and not (Terminated)) do begin
case pBuf^[i] of
。。。。
end;
Sleep(1); // Give other processes a chance
if Terminated then //the user has decided to stop the process
TerminateProcess(pi.hProcess, 0);
until ((Exit_Code <> STILL_ACTIVE) //process terminated (normally)
不知道是不是与sleep(1)有关。。。。。。我的主程序也使用死循环{ sleep(20); application.ProcessMessages;}来等待命令行执行完毕的。。。。。
var
bdosstop:Boolean;
function rundos(const cmd:String):Boolean;
begin
bdosstop:=false;
FormMain.DOScmd.CommandLine:=cmd;
FormMain.DOScmd.Execute;
while not bdosstop do
Begin
application.ProcessMessages;
sleep(20);
End;
result:=true;
end;
procedure TFormMain.DOScmdTerminated(Sender: TObject);
begin
bdosstop:=true;
end;
两个sleep有冲突???