Ctrl-Z in windows and byLine()
dsimcha
dsimcha at yahoo.com
Wed Oct 12 12:32:29 PDT 2011
Probably related:
http://d.puremagic.com/issues/show_bug.cgi?id=3425
== Quote from Steven Schveighoffer (schveiguy at yahoo.com)'s article
> On Wed, 12 Oct 2011 12:31:10 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
> > Got this from a reader:
> >
> > =======================
> > I'm testing on Windows the code below, based on your errata changes for
> > p8, print 1. It works ok if on console I enter some characters, but if I
> > terminate console input with ctrl-z, then there is an error exit of the
> > program. So, does this code need some exception handler to handle the
> > immediate end of input from console?
> >
> > void dict1_4()
> > {
> > size_t[string] dict; // see errata use size_t
> > foreach (line; stdin.byLine()){
> > foreach (word; splitter(strip(line))){ // see errata required
> > std.algorithm
> > if (word in dict) continue;
> > auto newID = dict.length;
> > dict[word.idup] = newID; // see errata required idup
> > writeln(newID, '\t', word);
> > }
> > }
> >
> > }
> > =======================
> >
> > I thought Ctrl-Z simply sends EOF to the reader, so this should work.
> > What is byLine() doing wrong?
> My guess would be the pipes issue with DMC. I'd have to have more
> information to be sure.
> Specifically, when an attempt to read from a closed pipe occurs, Windows
> flags this as an EPIPE error, but DMC incorrectly flags it as an EBADF
> (bad file descriptor).
> -Steve
More information about the Digitalmars-d
mailing list