Jump to content
Excelsior Forums
Sign in to follow this  

Detecting EOF of pipeline input

Recommended Posts

I have a problem in detecting EOF of stdin when it is piped.

The following is a simple version of cat, which handles only StdInChan.

    MODULE simplcat;

    FROM STextIO IMPORT ReadChar, SkipLine, WriteChar, WriteLn;

    FROM SIOResult IMPORT ReadResults, ReadResult;


        ch: CHAR;



      WHILE ReadResult() <> endOfInput DO

        IF ReadResult() = endOfLine THEN

          WriteLn(); SkipLine()


          WriteChar(ch) END;

        ReadChar(ch) END END simplcat.

Compile this module on Windows XP, type

    simplcat <simplcat.mod

and you will have no problem.  But reading from pipeline, e.g.

    simplcat <simplcat.mod | simplcat

    type simplcat.mod | simplcat

etc. will, after printing all the lines,  cause RTS exception.

Errinfo.$$$ is like this:


    #RTS: unhandled exception #4: IOException.hardDeviceError 0000006DH

    00000226  00000000  d:\work\simplcat.exe

    00001CD8  00000000  d:\work\simplcat.exe

    00001BA4  00000000  d:\work\simplcat.exe

    000031D9  00000000  d:\work\simplcat.exe

    00004116  00000000  d:\work\simplcat.exe

    000019C1  00000000  d:\work\simplcat.exe

    000024C3  00000000  d:\work\simplcat.exe

    00001FDA  00000000  d:\work\simplcat.exe

    00000065  00000000  d:\work\simplcat.exe

I have no idea who is to blame, you or Microsoft.

Does it occur only in Japan, maybe?

Could you try the module on your XP computer?

Other observations:

The error does not occur if ReadToken is used instead of ReadChar.

But it does occur if ReadRestLine is used.

I downloaded XDS on May 31, 2005.

My system is Windows XP Home Edition Service Pack 2 from Microsoft Japan.

Share this post

Link to post
Share on other sites

I wrote a simple Delphi program to check console:

program scat;

{$Apptype console}


  ch: char;


  while not eof do






Well, it works fine as "scat.exe < scat.dpr | scat.exe"

I think that ReadChar has an error because Delphi's code makes some checks while opening text file (and console too).

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this