How do I write to stdout from Delphi console application?
Here's what I have tried. I have rigged this simple test app according to infos I could find, to read a file from disk and output it to console stdout:
program ConsoleOut;
{$APPTYPE CONSOLE}
uses
Classes, Windows, SysUtils;
var
S: TMemoryStream;
OutputStream: THandleStream;
ss: string;
Buffer: PByte;
i: Integer;
begin
S := TMemoryStream.Create;
S.LoadFromFile('1.jpg');
S.Seek(0, soFromBeginning);
//Am I right that from now on writing to OutputStream will write to stdout?
OutputStream := THandleStream.Create(GetStdHandle(STD_OUTPUT_HANDLE));
GetMem(Buffer, S.Size);
S.ReadBuffer(Buffer^, S.Size);
i := OutputStream.Write(Buffer^, S.Size); //i = 0 here for some reason
FreeMem(Buffer, S.Size);
Writeln(i, ' byte written to output');
Readln(ss); //Don't exit app to read previous line
S.Free;
end.
But for some reason it fails. Could you please direct me into proper way of writing to stdout?