read till EOF from stdin
frame
frame86 at live.com
Fri Dec 11 11:05:59 UTC 2020
On Friday, 11 December 2020 at 02:31:24 UTC, kdevel wrote:
> auto s = cast (string) stdin.byChunk(4).join;
>
> As strace reveals the resulting program sometimes reads twice
> zero
> characters before it terminates:
>
> read(0, a <-- A,
> return
> "a\n", 1024) = 2
> read(0, "", 1024) = 0 <-- ctrl+d
> read(0, "", 1024) = 0 <-- ctrl+d
>
> Any comments or ideas?
I see expected behaviour here if you use a buffer of length 4. I
don't know what you want to achieve here. If you want to stop
reading from stdin, you should check for eof() instead. You
should not check yourself for the character. eof() can be lock in
by multiple ways and it is the only correct way to handle all of
them.
More information about the Digitalmars-d-learn
mailing list