[Issue 10467] readln problem with CTRL-Z

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Jun 24 14:58:00 PDT 2013


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


monarchdodra at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra at gmail.com


--- Comment #1 from monarchdodra at gmail.com 2013-06-24 14:57:58 PDT ---
(In reply to comment #0)
> If at the input prompt I give a Ctrl-Z the while loop seems to go in an
> infinite loop:
> 
> >dmd -run temp.d
> Input: ^Z
> Input: Input: Input: Input: Input: Input: Input: Input: Input: Input: Input:
> Input: Input: Input: Input: Input: ...

Just for the record, what *would* the correct behavior be? The stream is at
eof, so stdin has no need to wait for user input, and if you ask for a line,
you get "" ...

A "correct" program would have either:
while (stdin.isOpen && !stdin.eof && !stdin.error) //Meh...
Or...
string s;
while ((s = stdin.readln(line)).length) //very good!
Or...
char[] line;
while (stdin.readln(line)) //very good!

For the record, I don't think readln can throw an exception, since the "common
semantic" is "read lines until the read fails, then check it failed because you
have reached eof"...

So... yeah... Doesn't seem like a bug to me, just a program that wasn't
designed to handle stdin's eof...

-- 
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