4

I'm using mintty via Git-for-Windows and CPython35-32. Why does Python think it's not attached to a terminal?

$ python -c "import sys; print(sys.stdout.isatty())"
False

Interestingly, I also have a problem that I can not start an interactive session of Python inside the mintty. It might be related to this issue

$ python
<nothingness here...>
Niklas R
  • 16,299
  • 28
  • 108
  • 203

2 Answers2

4

mintty's console emulation uses pipes to emulate a tty behind the scenes which confuses native programs checking to see if they are attached to a tty. In your case Python's isatty() sees stdout as being attached to pipe due to the fake tty and returns False.

This is another example of mintty issue #56 - Improve support for native console programs. The mintty wiki entry "Input/Output interaction with alien programs" points out you can work around the problem by using a wrapper like winpty when running the problem program within mintty.

The git commits mentioned by @vonc only work around the problem in the git program itself - they won't impact other programs (such as Python running in git-for-window's mintty) which would need to implement git's workaround in their own source.

Anon
  • 6,306
  • 2
  • 38
  • 56
0

You might want to try that with Git 2.12 (Q1 2017)

See commit a9b8a09 (22 Dec 2016) by Jeff Hostetler (jeffhostetler).
See commit 8692483 (22 Dec 2016) by Alan Davies (scooter6386).
See commit fee807c (22 Dec 2016) by Johannes Schindelin (dscho).
(Merged by Junio C Hamano -- gitster -- in commit 58fcd54, 27 Dec 2016)

mingw: replace isatty() hack

Git for Windows has carried a patch that depended on internals of MSVC runtime, but it does not work correctly with recent MSVC runtime.
A replacement was written originally for compiling with VC++.

The patch in this message is a backport of that replacement, and it also fixes the previous attempt to make isatty() tell that /dev/null is not an interactive terminal.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250