Winpty和Git Bash [英] Winpty and Git Bash

查看:653
本文介绍了Winpty和Git Bash的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到的问题与 Python无法正常工作在git bash 的命令行中,在Git Bash中,当我键入Python时,它只是挂起.

I had the same issue as Python not working in the command line of git bash, where in Git Bash, when I type Python, it just hangs.

但是,键入winpty python效果很好.

winpty到底是什么?上面的命令为什么有用?

What exactly is winpty? Why is the above command useful?

推荐答案

winpty 是Windows软件包,提供类似于Unix pty-master的接口,用于与Windows控制台程序进行通信.

winpty is A Windows software package providing an interface similar to a Unix pty-master for communicating with Windows console programs.

这就是为什么您需要在此描述的原因:

That is why you need it as described here:

该软件通过使用新的隐藏控制台窗口启动winpty-agent.exe进程来工作,该窗口在控制台API和终端输入/输出转义码之间架起了桥梁.它会轮询隐藏的控制台的屏幕缓冲区以查找更改,并生成相应的输出流.

The software works by starting the winpty-agent.exe process with a new, hidden console window, which bridges between the console API and terminal input/output escape codes. It polls the hidden console's screen buffer for changes and generates a corresponding stream of output.

rprichard/winpty 提及:

该软件包包括一个库(libwinpty)和一个用于Cygwin和MSYS的工具,用于在Cygwin/MSYS pty中运行Windows控制台程序.

The package consists of a library (libwinpty) and a tool for Cygwin and MSYS for running Windows console programs in a Cygwin/MSYS pty.

如" mintty/mintty提示":

与使用本机Windows API进行命令行用户交互(控制台模式")的程序进行交互时,会观察到许多不良影响;这是 pty不兼容问题

When interacting with programs that use a native Windows API for command-line user interaction ("console mode"), a number of undesirable effects are observed; this is the pty incompatibility problem and the character encoding incompatibility problem.
This basically affects all programs not compiled in a cygwin or msys environment (and note that MinGW is not msys in this context).

作为一种解决方法,可以使用winpty作为包装程序来调用Windows程序.

As a workaround, you can use winpty as a wrapper to invoke the Windows program.


所以:


So:

为什么许多工具可以在普通CygWin中工作,但其中一些工具也需要winpty?

Why do many tools work in plain CygWin but some of them also need winpty?

(在Python中) msys2/MINGW-packages问题2645

This was asked (specifically for Python) in msys2/MINGW-packages issue 2645

使用winpty会产生非零的成本,而且在大多数情况下,薄荷的效果还是不错的.
您的问题源于尝试使用mingw python(这是Windows的本机版本),因此希望可以在Windows控制台中使用它.
mintty使用管道进行输入/输出,因此对于大多数程序而言,它似乎不是合适的终端.

there's a non-zero cost associated with using winpty, and most of the time, mintty works fine anyway.
Your problem stems from trying to use mingw python which is a native windows build, and hence expects it to be used from a windows console.
mintty uses pipes for input/output, so it doesn't look like a proper terminal to most programs.

另一方面,如果您使用msys2(或cygwin)python(例如/usr/local/bin/python2),则一切正常.

On the other hand, if you use msys2 (or cygwin) python (.e.g /usr/local/bin/python2), everything just works.

(通过 msys2/MINGW-packages PR 2675 ,python3可以正确检测到终端)

(With msys2/MINGW-packages PR 2675, python3 detects the terminal correctly)

这篇关于Winpty和Git Bash的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆