【问题标题】:Git-for-Windows Mintty sys.stdout.isatty() returns FalseGit-for-Windows Mintty sys.stdout.isatty() 返回 False
【发布时间】:2016-12-01 13:35:15
【问题描述】:

我通过 Git-for-Windows 和 CPython35-32 使用 mintty。为什么 Python 认为它没有连接到终端?

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

有趣的是,我还有一个问题是我无法在 mintty 中启动 Python 的交互式会话。可能和这个问题有关

$ python
<nothingness here...>

【问题讨论】:

标签: windows mintty


【解决方案1】:

mintty's console emulation uses pipes to emulate a tty 在幕后混淆了本地程序检查它们是否附加到 tty。在您的情况下,Python 的 isatty() 将 stdout 视为由于假 tty 而附加到管道并返回 False。

这是mintty issue #56 - Improve support for native console programs 的另一个示例。 mintty wiki entry "Input/Output interaction with alien programs" 指出,在 mintty 中运行问题程序时,您可以使用 winpty 之类的包装器来解决该问题。

@vonc 提到的 git 提交只能解决 git 程序本身的问题——它们不会影响其他需要在它们的自己的来源。

【讨论】:

  • 有趣。 +1
【解决方案2】:

您可能想在 Git 2.12(2017 年第一季度)上尝试一下

参见commit a9b8a09(2016 年 12 月 22 日)Jeff Hostetler (jeffhostetler)
commit 8692483(2016 年 12 月 22 日)Alan Davies (scooter6386)
请参阅 Johannes Schindelin (dscho)commit fee807c(2016 年 12 月 22 日)。
(由 Junio C Hamano -- gitster -- 合并于 commit 58fcd54,2016 年 12 月 27 日)

mingw:替换isatty() hack

Git for Windows 带有一个依赖于 MSVC 运行时内部的补丁,但它不能与最近的 MSVC 运行时正常工作。
最初是为使用 VC++ 编译而编写的替代品。

此消息中的补丁是该替换的反向移植,它还修复了先前尝试使isatty() 告诉/dev/null 不是交互式终端。

【讨论】:

    猜你喜欢
    • 2015-11-17
    • 2018-11-01
    • 1970-01-01
    • 2012-04-17
    • 2017-08-10
    • 2020-04-26
    • 2016-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多