Hmm, but why does the following work then ? $ ./pharo --headless Pharo.image eval '(FileStream stdin next: 3)' 123 '123' The binary case is an error though, for sure. And Zn character decoding works on binary streams, while the buffering streams read in blocks. And it always comes back to 'stdin is handled specially', is that so in C, generally speaking ? I am still digging though. I will send you some code later on.
On 11 Apr 2018, at 19:08, Alistair Grant <akgrant0710@gmail.com> wrote:
Hi Sven,
On 11 April 2018 at 18:53, Sven Van Caekenberghe <sven@stfx.eu> wrote:
Something is off (and/or I am getting crazy, probably both).
$ ./pharo --headless Pharo.image eval '(FileStream stdin binary; next: 3)' 123 #[49]
??
This should return #[49 50 51] AFAIK.
I haven't checked properly, but I can take a guess at this...
The file read primitive in FilePlugin tries to read from stdin 1 character at a time (presumably to get around the line buffering that is done, but I haven't gone through the history. At one time I think it modified the terminal settings, but that code is #if'd out). For all other streams it attempts to read the requested number of characters.
StandardFileStream>>readInto:startingAt:count: assumes that primitiveFileRead will always attempt to read count bytes, but it actually only attempts to read 1.
Cheers, Alistair