[Issue 3425] StdioException on end of stdin on Windows

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 28 17:09:22 PST 2011


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


Max Vilimpoc <max at vilimpoc.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |max at vilimpoc.org


--- Comment #3 from Max Vilimpoc <max at vilimpoc.org> 2011-12-28 17:09:15 PST ---
(In reply to comment #2)
> You can work around the issue by testing for eof  on the first line in the
> loop. This works with no error.   
> 
>     foreach(elem; stdin.byLine()) {
>         if (stdin.eof()) break;
>         writeln(elem);
>     }

This didn't work for me, when using the example program on the D homepage:

    import std.stdio;

    void main()
    {
        ulong lines = 0;
        double sumLength = 0;
        foreach(line; stdin.byLine())
        {
            if (stdin.eof()) break;

            ++lines;
            sumLength += line.length;
        }

        writeln("Average line length = ", lines ? sumLength / lines : 0);
    }

I still get:

    std.stdio.StdioException at std\stdio.d(2159): Bad file descriptor

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list