12.01.2015, 20:48
|
Прохожий
|
|
Регистрация: 08.04.2014
Сообщения: 26
Версия Delphi: Delphi 7
Репутация: 10
|
|
Глюки в командной строке
Есть вот такой код:
Код:
function TForm1.RunCmd(CommandLine: string): boolean;
type
OEMString = type AnsiString(CP_OEMCP);
var
I, dwAvail: byte;
OEMStr: OEMString;
U: UnicodeString;
Flag: boolean;
tRead, cWrite: THandle;
dwRead: cardinal;
SA: TSecurityAttributes;
PI: TProcessInformation;
SI: TStartupInfo;
begin
Result:=False;
SA.nLength:=SizeOf(SECURITY_ATTRIBUTES);
SA.bInheritHandle:=True;
SA.lpSecurityDescriptor:=nil;
if not CreatePipe(tRead, cWrite, @SA, 0) then Exit;
ZeroMemory(@SI, SizeOf(TStartupInfo));
SI.cb:=SizeOf(TStartupInfo);
SI.dwFlags:=STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
SI.wShowWindow:=SW_HIDE;
SI.hStdOutput:=cWrite;
if CreateProcess(nil,
PChar(CommandLine),
nil,
nil,
True,
0,
nil,
nil,
SI,
PI)
then
begin
CloseHandle(PI.hProcess);
CloseHandle(PI.hThread);
CmdMemo.Clear;
Flag:=True;
while Flag do
begin
for I:=0 to 9 do
begin
PeekNamedPipe(tRead, nil, 0, nil, @dwAvail, nil);
if dwAvail>0
then
begin
Flag:=True;
Break;
end
else Flag:=False;
Sleep(100);
end; //for I:=
if dwAvail>0
then
begin
SetLength(OEMStr, dwAvail);
ReadFile(tRead, PChar(OEMStr)^, Length(OEMStr), dwRead, Nil);
U := OEMStr;
CmdMemo.Lines.Add(U);
Application.ProcessMessages;
Result:=True;
end; // if dwAvail
end; // while Flag
end; // if CreateProcess
end;
При выполнении получается такая картинка: скрин на яндексе
То есть посередине пятой строки программа вешается. Понимаю, что где-то закрался косяк (и не один)), но не понимаю, где
p.s.: Delphi XE3
|