在 cygwin 下的 Windows 应用程序中有时无法识别输入密钥

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/202405/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:27:26  来源:igfitidea点击:

enter key sometimes not recognized in windows apps under cygwin

windowscygwin

提问by rmeador

At work, I use Cygwin a lot because it offers me a small oasis in the vast desert of Windows. I inevitably end up running some non-Cygwin programs through the bash shell, such as build scripts (batch files created in-house) and the Subversion CLI binaries (I have the Windows ones installed). 99% of the time, I don't have any problems using this setup. The other 1%, however, causes a strange issue:

在工作中,我经常使用 Cygwin,因为它为我提供了广阔的 Windows 沙漠中的一小片绿洲。我不可避免地最终通过 bash shell 运行了一些非 Cygwin 程序,例如构建脚本(内部创建的批处理文件)和 Subversion CLI 二进制文件(我安装了 Windows 的)。99% 的情况下,我使用此设置没有任何问题。然而,另外 1% 会导致一个奇怪的问题:

With both the build scripts and SVN, most of the time the enter key is interpreted correctly. For instance, I'll kick off the database creation script and it will prompt me for the server name. I type in "localhost" and hit enter. Everything's fine. Then it gets to the end, if there are errors, and prints things out using more. No key that I press is recognized by more. I have to Ctrl-C out of it.

对于构建脚本和 SVN,大多数情况下输入键都被正确解释。例如,我将启动数据库创建脚本,它会提示我输入服务器名称。我输入“localhost”并按回车键。一切安好。然后它会结束,如果有错误,并使用more. 没有识别我按下的任何键more。我必须 Ctrl-C 退出它。

Similarly, if I do a Subversion update, normally everything is fine. In the case where the interactive conflict resolution happens, however, I'll usually type in "tf" for "theirs-full" and hit enter, but nothing happens. I have to Ctrl-C out of it and re-run the update with force merge or use TortoiseSVN in Windows to do it.

同样,如果我进行 Subversion 更新,通常一切都很好。然而,在交互式冲突解决发生的情况下,我通常会输入“tf”作为“他们的完整”并按回车键,但没有任何反应。我必须 Ctrl-C 退出它并使用强制合并重新运行更新或在 Windows 中使用 TortoiseSVN 来执行此操作。

Any idea why Cygwin seems to randomly not be passing the enter key through to the programs? I considered that it may have something to do with Unix vs Windows style line endings, so I've tried typing those characters manually, but that doesn't seem to make a difference. Thanks.

知道为什么 Cygwin 似乎随机没有将回车键传递给程序吗?我认为它可能与 Unix 与 Windows 风格的行尾有关,所以我尝试手动输入这些字符,但这似乎没有什么区别。谢谢。

Edit: I just had this happen to me again and I realized something. It was SVN prompting me for a password. I typed in the password, which it echoed to the screen (bad) and hit enter... nothing. Hit enter a few more times, the cursor moves, but nothing happens. I hit Ctrl-C and it dumps me back to bash, which then says "bash: [my password]: command not found" followed by a number of new prompts equal to the number of times I hit the enter key. So what happened is the input never made it to SVN, but somehow got read by bash after SVN exited. I thought that may help someone figure out what is going on.

编辑:我刚刚再次发生这种情况,我意识到了一些事情。这是SVN提示我输入密码。我输入了密码,它在屏幕上回显(不好)并按回车键......什么都没有。再按几次回车,光标移动,但没有任何反应。我按了 Ctrl-C,它把我转回 bash,然后说“bash:[我的密码]:找不到命令”,然后是一些新的提示,等于我按回车键的次数。所以发生的事情是输入从未到达 SVN,但在 SVN 退出后不知何故被 bash 读取。我认为这可能有助于某人弄清楚发生了什么。

回答by DustinB

Unfortunately, I think you are hitting one of the issues of Cygwin and windows/dos console apps. See "Console Programs" at http://www.cygwin.com/cygwin-ug-net/using-effectively.html.

不幸的是,我认为您遇到了 Cygwin 和 windows/dos 控制台应用程序的问题之一。请参阅http://www.cygwin.com/cygwin-ug-net/using-effectively.html 上的“控制台程序” 。

It is just a limitation on windows console apps. This behavior is common for the windows myqsl cmd client and svn client, for example.

这只是 Windows 控制台应用程序的限制。例如,此行为对于 windows myqsl cmd 客户端和 svn 客户端很常见。

Here are some things to note -- I've successfully used this approach with both the Windows mysql as well as Windows svn clients:

这里有一些需要注意的事情——我已经成功地将这种方法用于 Windows mysql 和 Windows svn 客户端:

1) Try making sure you do NOT have "tty" in your CYGWIN environment variable and see if that helps (unset it in My Computer->properties->advanced->Environment Variables and close/restart any cygwin bash prompts).

1) 尝试确保您的 CYGWIN 环境变量中没有“tty”,看看是否有帮助(在我的电脑-> 属性-> 高级-> 环境变量中取消设置并关闭/重新启动任何 cygwin bash 提示)。

2) Do not use RXVT -- instead, use the basic Cygwin cmd prompt. This is because RXVT implies "tty" and will break #1 above.

2) 不要使用 RXVT——而是使用基本的 Cygwin cmd 提示符。这是因为 RXVT 意味着“tty”并且会破坏上面的#1。

3) Try finding a "native" Cygwin package for the cmds you are having issues with instead of using the Windows cmds. (I haven't found a 1.6 svn client for cygwin yet, though.)

3) 尝试为您遇到问题的 cmd 找到一个“本机”Cygwin 包,而不是使用 Windows cmd。(不过,我还没有为 cygwin 找到 1.6 svn 客户端。)

Good luck! Dustin

祝你好运!达斯汀

回答by Vic

The lengthy discussion on the mintty project is here - http://code.google.com/p/mintty/issues/detail?id=56

关于 mintty 项目的冗长讨论在这里 - http://code.google.com/p/mintty/issues/detail?id=56

One solution mentioned which worked in my case (entering authentication passwords for native subversion) is conin- http://code.google.com/p/mintty/downloads/detail?name=conin-0.0.2.zip&can=1&q=label%3ADevelopment

提到的一种在我的情况下有效的解决方案(输入本机颠覆的身份验证密码)是conin- http://code.google.com/p/mintty/downloads/detail?name=conin-0.0.2.zip&can=1&q=label %3A发展

$ conin svn list https://{repo}
Password for 'user': ******