On 5/3/2017 4:26 AM, Florian Balmer wrote:
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.
...which is why I labelled it a "suggested" patch. :)
I know next to nothing about windows api's, however the current code
does not work when using mintty. It was extremely frustrating trying to
enter a password and finding that it did not read what I had typed.
Ultimately I had to refer to the source code to figure it out.
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users