Hi Damien, Vincent and Guille,

Just a disclaimer: despite having done some work on this, I don't
consider myself an expert.  If someone else has a better explanation,
please jump in.


Damien wrote on discord:
> is there a notion of standard input/output on windows ?

Yes, console applications can use stdio.  PharoConsole.exe when run from
a command prompt has stdio.  (Note that cygwin terminals are different
and don't support stdio (since Pharo uses the native windows functions)).


> looks like Alistair added the possibility to open files by number,

Holger Freyther deserves the credit here.  My clumsy git merging left
his name out as the author (sorry Holger!).


> that's probably what was missing at the time Stdio was introduced

I'm not sure that opening files by fd would be useful in this particular
case.

There are three ways to access files on Windows:

file descriptor - posix compatibility
FILE* - posix compatibility
HANDLE - windows native

The VM uses native operations for file i/o on Windows, e.g.
Read/WriteConsole() for stdio (including pipe redirection of stdio).

Mixing file descriptors and FILE* is possible if you're careful.  I
don't know how to mix fd / FILE* and HANDLEs.  It's probably better to
stick with using native windows functions most of the time.  We included
these functions on Windows since they exist, and there are probably some
use cases, but you need to know what you're doing.

File class>>stdioHandles calls primitiveFileStdioHandles() which
eventually opens the stdio streams (if possible) using the Windows
native GetStdHandle() function.


> I suspect File needs a nameless variant (I'm not certain how pipes
> work in unix but I doubt echo foo | cat ever touches the filesystem)

That's my understanding (it doesn't touch the file system).


> hmm but the short-term bug is that the TTY logic in Stdio >>
> #standardIOStreamNamed:forWrite: fails when all 3 standard streams are
> redirected

OK, my understanding of what you are saying is that if all 3 io streams
are redirected the method incorrectly determines that a console isn't
present and so falls back to calling #createStdioFileFor:.

More below...


> I also don't understand the assumption there

Vincent Blondeau added / modified these methods, so he may be able to
provide more information.

I think the assumption is that if any of the stdio files are connected
to a TTY. then it is possible to open all the stdio files.  If none are
present, then (on Windows) create regular files to act as a substitute.

The problem is that it only tests for a TTY, when what we really want is
a TTY or a file or a pipe.


Assuming I've understood correctly, maybe try modifying (sorry for the
loss of formatting, only the last line is changed):


File class>>stdioDescriptorIsATTY
^ (0 to: 2)
anySatisfy: [ :fdNum |
| res |
res := self fileDescriptorType: fdNum.
res between: 1 and: 3 ]


We'd need to rename the method, since it is misleading, but it looks
like it better represents the intended use.



Cheers,
Alistair

Reply via email to