Почему у меня все логи сыпятся в err хотя должны разделяться
type
TArg<T> = reference to procedure(const Arg: T);
procedure CaptureConsoleOutput(const ACommand, AParameters: String; Log, Err: TArg<PAnsiChar>);
const
CReadBuffer = 2400;
var
saSecurity: TSecurityAttributes;
hRead: THandle;
hWrite: THandle;
hError, hWriteErr: THandle;
suiStartup: TStartupInfo;
piProcess: TProcessInformation;
pBuffer: array [0 .. CReadBuffer] of AnsiChar;
dBuffer: array [0 .. CReadBuffer] of AnsiChar;
dRead: DWORD;
dRunning: DWORD;
dAvailable: DWORD;
CreationFlags : DWORD;
ConsoleOutputCP: Cardinal;
begin
saSecurity.nLength := SizeOf(TSecurityAttributes);
saSecurity.bInheritHandle := true;
saSecurity.lpSecurityDescriptor := nil;
if CreatePipe(hRead, hWrite, @saSecurity, 0) and CreatePipe(hError, hWriteErr, @saSecurity, 0) then
try
FillChar(suiStartup, SizeOf(TStartupInfo), #0);
suiStartup .cb := SizeOf(TStartupInfo);
suiStartup.hStdInput := hRead;
suiStartup.hStdOutput := hWrite;
suiStartup.hStdError := hError;
suiStartup.dwFlags := STARTF_USESTDHANDLES or STARTF_USESHOWWINDOW;
suiStartup.wShowWindow := SW_HIDE;
CreationFlags := CREATE_DEFAULT_ERROR_MODE or
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS;
if CreateProcess(nil, PChar(ACommand + ' ' + AParameters), @saSecurity, @saSecurity, true, CreationFlags, nil, nil, suiStartup, piProcess) then
try
CloseHandle(hWrite);
CloseHandle(hWriteErr);
repeat
dRunning := WaitForSingleObject(piProcess.hProcess, 50);
PeekNamedPipe(hRead, nil, 0, nil, @dAvailable, nil);
if (dAvailable > 0) then
repeat
dRead := 0;
ReadFile(hRead, pBuffer[0], CReadBuffer, dRead, nil);
pBuffer[dRead] := #0;
OemToCharA(pBuffer, dBuffer);
Log(dBuffer);
until (dRead < CReadBuffer);
PeekNamedPipe(hError, nil, 0, nil, @dAvailable, nil);
if (dAvailable > 0) then
repeat
dRead := 0;
ReadFile(hError, pBuffer[0], CReadBuffer, dRead, nil);
pBuffer[dRead] := #0;
OemToCharA(pBuffer, dBuffer);
Err(dBuffer);
until (dRead < CReadBuffer);
until (dRunning <> WAIT_TIMEOUT);
finally
CloseHandle(piProcess.hProcess);
CloseHandle(piProcess.hThread);
end;
finally
CloseHandle(hRead);
CloseHandle(hWrite);
end;
end;
а вот так выглядят принимающие процедуры
procedure TForm2.ToMemo(const Line: PAnsiChar);
begin
Memo1.Lines.Add(String(Line));
Label1.Caption := IntToStr(Memo1.Lines.Count);
Application.ProcessMessages;
end;
procedure TForm2.ToError(const Line: PAnsiChar);
begin
Memo2.Lines.Add(String(Line));
Label2.Caption := IntToStr(Memo2.Lines.Count);
Application.ProcessMessages;
end;
что я делаю не так?
P.S. запускаю ffmpeg.exe