Python Forum
is stdin a console - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: General (https://python-forum.io/forum-1.html)
+--- Forum: News and Discussions (https://python-forum.io/forum-31.html)
+--- Thread: is stdin a console (/thread-36298.html)



is stdin a console - Skaperen - Feb-06-2022

is there a portable way to determine if reading stdin will read from the console? i know how to do this in Linux and BSD, but not in MS Windows. a single portable way would be simpler, cleaner, and more pythonic (IMHO) than 2 or 3 OS checks and OS-specific tests for a console (in a function, of course).


RE: is stdin a console - Gribouillis - Feb-06-2022

Have you tried sys.stdin.isatty() ?


RE: is stdin a console - Skaperen - Feb-06-2022

not in MS Windows. does "tty" have a meaning in MS Windows? for POSIX can it be true for a serial port? the library reference doc is not detailed/specific enough to say. i want to know if it is the console. i want False for a serial port even though a user could log in there and run a shell from a connected terminal.