[fpc-pascal] TFileStream and stdin - how to make this work?

Bernd Kreuss prof7bit at googlemail.com
Sun Oct 3 15:05:10 CEST 2010


Hi,

this might be a stupid question but I find myself again struggling with
file IO and stdin/stdout. I am trying to do the following:

StdIn := TFileStream.Create('/dev/stdin', fmOpenRead);

and later on i want to poll whether there is something to read. I want
to try reading binary data that will be piped to my application and i
need to poll (non blocking!) and in case of incoming data read the first
byte to determine the type of message that has arrived and then read the
rest.

The Stream seems to be able to read when there is something to read on
stdin but I cannot find any way to actually test whether the ReadByte()
will block (nothing to read) or whether there is data available.

the properties size and position both are always $ffffffffffffffff and
the stream has no eof property.

Can this be done at all? And is my way of opening the stream correct?
What would be a more platform independent way of opening the stdin as a
stream to read binary data or is there a different and better way to do
this, maybe a stream is not the correct thing for this at all? How do I
poll and read binary data from stdin?

Bernd



More information about the fpc-pascal mailing list