Mintty is the default console for MSYS2. I don't know what MinGW or Cygwin uses.
In generic/tclMain.c tcl_interactive is set based on the result of isatty(0). On windows with mintty this is not sufficient. Thus, if one starts tclsh/wish while using mintty, there is no "% " prompt.
1. From https://msdn.microsoft.com/en-us/library/ms235388.aspx the recommendation is to use _isatty(). Also one should use _fileno(stdout) rather than hard-coding a "0".
2. From a discussion of comp.lang.tcl about whether Tcl could determine if a file descriptor (stdout) was really a terminal, the conclusion I came to was that it was not possible (at least on windows).
3. I encountered this issue also with fossil -- it did not read a password typed interactively when I used mintty.
As I know next to nothing about windows api's, I will quote an email from the fossil.users list in response to my naive patch to fossil. The email points to several resources that might address a solution.
Date: Wed, 3 May 2017 11:26:42 +0200
To: [email protected]
Subject: Re: [fossil-users] Suggested patch for src/user.c (password prompt)
Just because I have done some research about this topic recently, and find it interesting, please allow me to ask why you can make any assumptions regarding STDIN, after only testing STDERR? Couldn't each of the standard handles be redirected individually, as in "COMMAND <input.txt 1>nul 2>errors.log"?
To distinguish console handles from files, pipes and other redirected devices on Windows, MSDN recommends using GetConsoleMode(), as for example mentioned in the documentation for WriteConsole():
https://msdn.microsoft.com/en-us/library/windows/desktop/ms687401.aspx
"... determine whether the output handle is a console handle (one method is to call the GetConsoleMode function and check whether it succeeds) ..."
A more detailed test from Michael Kaplan, similar to earlier versions of MSVCRT (current UCRT seems to rely on a combined test of isatty(), GetFileType() and GetConsoleMode(), now):
http://archives.miloush.net/michkap/archive/2008/03/18/8306597.html
A comment by Raymond Chen why GetFileType() alone (as used by some isatty() CRT implementations) is not sufficient to detect a console handle:
https://blogs.msdn.microsoft.com/junfeng/2005/07/08/how-do-i-know-if-console-handle-is-redirected/
My investigations were about output handles, but GetConsoleMode() can also be used with input handles.
|