I think he means that stderr should not write to stdout,
He needs to configure stderr to redirect to file or a stream that can be used with a error reporting component. AFAIK there are several examples on the form. It is a recurring issue.
The Lazarus IDE uses this redirection itself.
If there is no redirection then the only way is to redirect stderr to stdout.
Here's a utility unit I wrote that extends CreatePipeStream with a third writestream for stdErr:
unit ExtendedPipes;
{$mode objfpc}{$H+}
interface
uses
{$ifdef unix}baseunix,unix,{$endif}{$ifdef mswindows}jwaWindows,{$endif}Classes, SysUtils, Pipes,streamio;
procedure CreateExtPipeStreams(out ReadPipe: TInputPipeStream;
out WritePipe: TOutputPipeStream;
out ErrWritePipe: TOutputPipeStream);
implementation
procedure CreateExtPipeStreams(out ReadPipe: TInputPipeStream;
out WritePipe: TOutputPipeStream;
out ErrWritePipe: TOutputPipeStream);
var
Pipe1Read, Pipe1Write: THandle;
Pipe2Read, Pipe2Write: THandle;
begin
// Create first pipe (normal input/output)
if not CreatePipeHandles(Pipe1Read, Pipe1Write) then
raise EPipeError.Create('Failed to create primary pipe');
// Create second pipe (for stderr)
if not CreatePipeHandles(Pipe2Read, Pipe2Write) then
begin
CloseHandle(Pipe1Read);
CloseHandle(Pipe1Write);
raise EPipeError.Create('Failed to create stderr pipe');
end;
try
// Create the pipe stream objects
ReadPipe := TInputPipeStream.Create(Pipe1Read);
WritePipe := TOutputPipeStream.Create(Pipe1Write);
ErrWritePipe := TOutputPipeStream.Create(Pipe2Write);
// Redirect stderr to our error pipe
AssignStream(ErrOutput, ErrWritePipe);
Rewrite(ErrOutput);
except
// Cleanup if something goes wrong
CloseHandle(Pipe1Read);
CloseHandle(Pipe1Write);
CloseHandle(Pipe2Read);
CloseHandle(Pipe2Write);
raise;
end;
end;
end.
(I always had the plan to write that, this looked like a good opportunity to finally do it. I had a little help from deepseek, but quite a few manual changes necessary)
Use is the same as for CreatePipeStream, except stderr now has its own stream.