Gotowy przykład -> http://www.mediafire.com/file/kjvdm4bdelceonw/ExecuteConsole.7z/file
a tu konkretna funkcja
function ExecuteConsole(ExeName: string;Priority:cardinal):boolean;
const bufSize = 256;
var readPipe :THandle;
writePipe :THandle;
security :SECURITY_ATTRIBUTES;
info :STARTUPINFO;
process :PROCESS_INFORMATION;
buf :array[0..bufSize-1] of char;
bytesRead :DWord;
text :string;
textLen: Integer;
newLinePos :integer;
posLF, posCR: Integer;
progress:string;
line:string;
begin
result:=FALSE;
security.nLength:=sizeof(security);
security.lpSecurityDescriptor:=nil;
security.bInheritHandle:=TRUE;
if CreatePipe(readPipe, writePipe, @security, 0)=true then
begin
ZeroMemory(@info, sizeof(info));
with info do
begin
cb := sizeof( info );
dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;
wShowWindow := SW_HIDE;
hStdInput := 0;
hStdOutput := writePipe;
hStdError := writePipe;
end;
if CreateProcess(nil, PChar(ExeName), nil, nil, TRUE, Priority, nil, nil, info, process)=true then
begin
CloseHandle( writePipe );
text:='';
textLen := 0;
while ReadFile( readPipe, buf, bufSize, bytesRead, nil)=true do
begin
textLen := Length(text);
text:=text+buf;
textLen := textLen + bytesRead;
SetLength(text, textLen);
repeat
posLF := Pos(#10, text);
posCR := Pos(#13, text);
if (posLF > 0) then
if (posCR > 0) then
if (posLF < posCR) then
newLinePos := posLF
else
newLinePos := posCR
else
newLinePos := posLF
else
newLinePos := posCR;
if (newLinePos = 0) then break;
line := copy(text, 1, newLinePos-1);
if (newLinePos + 1 = posLF) or (newLinePos + 1 = posCR) then newLinePos := newLinePos + 1;
delete(text, 1, newLinePos);
form1.memo1.Lines.Add(line);
application.ProcessMessages;
until application.Terminated=true;
end;
if Length(text)>0 then
begin
form1.memo1.Lines.Add(line);
end;
Result := True;
end;
CloseHandle( readPipe );
end;
end;
Po skompilowaniu w Delphi 7 wszystko działa jak trzeba
Zaś po przemieleniu w Delphi 10.3 nic się nie dzieje.