[Issue 387] New: When EOF of din is reached, a line of output is lost

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Sep 28 18:44:06 PDT 2006


http://d.puremagic.com/issues/show_bug.cgi?id=387

           Summary: When EOF of din is reached, a line of output is lost
           Product: D
           Version: 0.167
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: Phobos
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: smjg at iname.com


The following program should wait for an EOF from the standard input, and then
output two lines of text:

----------
import std.cstream;
import std.stdio;

void main() {
    while (din.getc != char.init) {}
    writefln("Line 1");
    writefln("Line 2");
}
----------

In fact, only "Line 2" gets printed.

I've experimented with writef, dout.writefln, dout.writef, dout.write(char),
dout.writeString and dout.writeLine, all with the same results.  The output is
also the same if the writefln statements are consolidated into one:

    writefln("Line 1\nLine 2");

The bug also bites if din.readLine is used:

    while (din.readLine != "") {}

Changing either or both lines of output to go to stderr also makes no
difference.

Mysteriously, if either input or output is redirected, or the program is at
either end of a pipe, then the bug doesn't show.

There's no obvious workaround.  Calling din.flush() or dout.flush() at any
point makes no difference.  While you could add a dummy line of output, this
would both break the program when the bug is fixed and break it with the
aforementioned redirection and piping.

This is likely to block people trying to write various Unix-style tools.


-- 




More information about the Digitalmars-d-bugs mailing list