Jump to page: 1 2
Thread overview
[Issue 387] New: When EOF of din is reached, a line of output is lost
Sep 29, 2006
d-bugmail
Sep 29, 2006
d-bugmail
Sep 29, 2006
d-bugmail
Sep 29, 2006
d-bugmail
Sep 29, 2006
Derek Parnell
Sep 29, 2006
Ary Manzana
Sep 29, 2006
BCS
Sep 30, 2006
Stewart Gordon
Sep 30, 2006
Frits van Bommel
Sep 30, 2006
d-bugmail
Oct 05, 2006
Walter Bright
Oct 07, 2006
Stewart Gordon
Oct 07, 2006
Walter Bright
Sep 30, 2006
d-bugmail
Sep 30, 2006
d-bugmail
Oct 14, 2006
d-bugmail
Oct 14, 2006
Walter Bright
May 28, 2011
Stewart Gordon
Apr 08, 2012
notna
May 12, 2012
Oleg Kuporosov
September 29, 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@digitalmars.com
        ReportedBy: smjg@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.


-- 

September 29, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=387





------- Comment #1 from digitalmars-com@baysmith.com  2006-09-29 00:15 -------
Works for me.

>dmd -run issue387.d
^Z
Line 1
Line 2

>

Window XP, DMD 0.167


-- 

September 29, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=387





------- Comment #2 from ddparnell@bigpond.com  2006-09-29 01:40 -------
Works for me too ...

c:\temp>type test.d
import std.cstream;
import std.stdio;

void main() {
    while (din.getc != char.init) {}
    writefln("Line 1");
    writefln("Line 2");
}
c:\temp>bud test
Path and Version : y:\util\bud.exe v3.03(2370)
  built on Wed Sep 20 16:16:41 2006

c:\temp>test <test.d
Line 1
Line 2

c:\temp>


-- 

September 29, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=387





------- Comment #3 from smjg@iname.com  2006-09-29 05:42 -------
So it works on WinXP.  It's 98SE I'm having trouble on.

(In reply to comment #2)
> c:\temp>test <test.d
> Line 1
> Line 2

My point is that it's when _not_ redirecting that the problem shows up.  For the record, what OS version are you on, Derek?


-- 

September 29, 2006
On Fri, 29 Sep 2006 10:42:22 +0000 (UTC), d-bugmail@puremagic.com wrote:

> http://d.puremagic.com/issues/show_bug.cgi?id=387
> 
> ------- Comment #3 from smjg@iname.com  2006-09-29 05:42 -------
> So it works on WinXP.  It's 98SE I'm having trouble on.
> 
> (In reply to comment #2)
>> c:\temp>test <test.d
>> Line 1
>> Line 2
> 
> My point is that it's when _not_ redirecting that the problem shows up.  For the record, what OS version are you on, Derek?

WinXP SP2. Is anyone still using Win98? ;-)


-- 
Derek Parnell
Melbourne, Australia
"Down with mediocrity!"
September 29, 2006
Derek Parnell wrote:
> On Fri, 29 Sep 2006 10:42:22 +0000 (UTC), d-bugmail@puremagic.com wrote:
> 
>> http://d.puremagic.com/issues/show_bug.cgi?id=387
>>
>> ------- Comment #3 from smjg@iname.com  2006-09-29 05:42 -------
>> So it works on WinXP.  It's 98SE I'm having trouble on.
>>
>> (In reply to comment #2)
>>> c:\temp>test <test.d
>>> Line 1
>>> Line 2
>> My point is that it's when _not_ redirecting that the problem shows up.  For
>> the record, what OS version are you on, Derek?
> 
> WinXP SP2. Is anyone still using Win98? ;-)
> 
> 

In Argentina, for instance, some people is still using Win98, because their computer isn't good enough to support WinXP. I also believe this happens in other countries...
September 29, 2006
Ary Manzana wrote:
> Derek Parnell wrote:
> 
>> Is anyone still using Win98? ;-)
>>
>>
> 
> In Argentina, for instance, some people is still using Win98, because their computer isn't good enough to support WinXP. I also believe this happens in other countries...

4 out of the 8 computers I am connected with are Win98
September 30, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=387





------- Comment #4 from smjg@iname.com  2006-09-30 11:47 -------
Alas, it's a bug with the OS.  I've tried the C stdio API (both DM and Borland implementations) and the Windows file I/O API with the same effect.  And I'm still lost for a workaround.

I can't even find any stream state information that can have anything to do with the problem.

But at least something that can be done now is to find out on which Windows versions the bug occurs.  We have that it works on XP and fails on 98SE.  This leaves 95, 98, ME, 2000 and Server 2003 to check if I haven't missed any.


-- 

September 30, 2006
Derek Parnell wrote:
<snip>
> WinXP SP2. Is anyone still using Win98? ;-)

Oh, you mean 98 as opposed to 98SE?  I don't know.

But my guess is that there are many people on older OSs who either:
- haven't been bothered to upgrade
- have acquired a second-hand or even third-hand computer
- are making the most of an old system that still works before throwing it away

I know somebody who was, until a year or three ago, still doing everything in MS-DOS.

Stewart.

-- 
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCS/M d- s:-@ C++@ a->--- UB@ P+ L E@ W++@ N+++ o K-@ w++@ O? M V? PS- PE- Y? PGP- t- 5? X? R b DI? D G e++++ h-- r-- !y
------END GEEK CODE BLOCK------

My e-mail is valid but not my primary mailbox.  Please keep replies on the 'group where everyone may benefit.
September 30, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=387





------- Comment #5 from fvbommel@wxs.nl  2006-09-30 12:22 -------
Stewart Gordons said:
> But at least something that can be done now is to find out on which Windows versions the bug occurs.  We have that it works on XP and fails on 98SE.  This leaves 95, 98, ME, 2000 and Server 2003 to check if I haven't missed any.

I think you missed previous NT versions.

Anyway, it works fine on Win2000:

--------------------------
D:\Temp>type test.d
import std.cstream;
import std.stdio;

void main() {
    while (din.getc != char.init) {}
    writefln("Line 1");
    writefln("Line 2");
}
D:\Temp>dmd test.d
d:\d\dmd\bin\..\..\dm\bin\link.exe test,,,user32+kernel32/noi;

D:\Temp>test.exe
^Z
Line 1
Line 2

D:\Temp>test.exe < test.d
Line 1
Line 2

D:\Temp>ver

Microsoft Windows 2000 [Version 5.00.2195]

D:\Temp>
--------------------------


-- 

« First   ‹ Prev
1 2