Hi,
I've been writing an app that takes a data feed from Stdin, and while I have it working using the code below, which works fine if you are running it on the commandline
ie sendstuff | MyApp
However I was trying to get the App to run inside the IDE by first piping the output to a file
sendstuff > xxx
and then in the run params having "< xxx", but it doesnt see the input as Stdin and you get a stream size of -1.
Anyone got any ideas how to be ablue to simulate the stdin properly so I can step through the code in the IDE, debugging via writeln really sucks.
Its a windows app atm, will eventually want to expand it so its windows/linux. Im using Delphi 12.2
John.
var
StdInHandle: THandle;
StdInStream: TStream;
Buffer: TBytes;
BytesRead: Integer;
begin
StdInHandle := GetStdHandle(STD_INPUT_HANDLE);
// Ensure the handle is valid
if StdInHandle = INVALID_HANDLE_VALUE then
begin
WriteErr('Invalid standard input handle.');
Exit;
end;
try
// Wrap the handle in a THandleStream for easier reading
StdInStream := THandleStream.Create(StdInHandle);
while StdInStream.Position < StdInStream.Size do
begin
SetLength(Buffer, StdInStream.Size);
BytesRead := StdInStream.Read(Buffer, StdInStream.Size);
// do stuff
end;