如何以及为什么QuickEdit模式在命令提示符冻结应用程序? [英] How and why does QuickEdit mode in Command Prompt freeze applications?

查看:728
本文介绍了如何以及为什么QuickEdit模式在命令提示符冻结应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近遇到了一个问题,在Windows上的命令提示符启用QuickEdit模式,并单击该窗口正在选择文本和挂起正在运行的程序。这显然是已知的行为 - 我发现了一些与它相关的问题:





应用程式如何「暂停」/「暂停」?该过程是否类似于* nix上的 SIGSTOP 信号?

解决方案 div>

这是非常的设计。当您的程序继续滚动控制台窗口的内容时,用户无法选择文本的合理方式。因此控制台主机程序只是停止读取stdout / stderr输出,并且程序挂起,直到用户完成操作。这可以更改,您必须致电获取+ SetConsoleMode()并关闭ENABLE_QUICK_EDIT_MODE选项。



请注意,此挂起与您执行暂停时基本上不同程序以远高于控制台主机可以消耗它的速率生成stdout输出。虽然这些延迟是有限的。



这不是用户可以停止你的程序的唯一方式,他也可以简单地按Ctrl + S。按Ctrl + Q再次恢复。如果您的年龄太大,那么您可能会将这些控制代码识别为 Xon / Xoff ,终端的握手字符。这是一个控制台真正的,一个终端的简单的仿真,他们在20世纪70年代使用的方式。这也可以改变,你必须停止依赖内置缓冲控制台输入,并切换到 ReadConsole()。或者通过关闭ENABLE_LINE_INPUT控制台选项,不确定自从您没有提到任何语言运行时之后的副作用,您必须尝试。



当然,终止你的程序是很容易的。你在stdin上得到EOF当用户键入Ctrl + Z,那应该结束你的程序。有Ctrl + C和Ctrl + Break的即时终止,无论你的程序在做什么。您可以使用 SetConsoleCtrlHandler(),但您不能阻止它。



如果默认行为是危险的,强烈建议你雇一个顾问。不知道谁写这个答案。


I recently ran into an issue with Command Prompt on Windows where QuickEdit mode was enabled and clicking the window was selecting text and hanging a running program. This is, apparently, known behaviour—I found a few questions related to it:

How is the application "paused"/"suspended"? Is the process similar to the SIGSTOP signal on *nix? (I am also interested in understanding why this functionality exists in the first place? It seems unintuitive and dangerous.)

解决方案

This is very much by design. There's no reasonable way a user can select text when your program keeps scrolling the content of the console window. So the console host program simply stops reading your stdout/stderr output and your program hangs until the user completes the operation. This can be changed, you'll have to call Get+SetConsoleMode() and turn off the ENABLE_QUICK_EDIT_MODE option.

Do note that this "hang" isn't fundamentally different from the execution pauses you get when your program generates stdout output at a rate far higher than the console host can consume it. Albeit that those delays are finite.

And it isn't the only way the user can stop your program, he can also simply press Ctrl+S. Pressing Ctrl+Q resumes it again. If you're old enough then you might recognize these control codes as Xon/Xoff, handshake characters for a terminal. Which is what a console really is, a simple emulation of a terminal the way they were used back in the 1970s. This can be changed too, you'll have to stop relying on the built-in buffered console input and switch to ReadConsole(). Or by turning off the ENABLE_LINE_INPUT console option, not so sure what side-effects that has since you didn't mention any language runtime, you'll have to try.

And of course terminating your program is very easy. You get EOF on stdin when the user types Ctrl+Z, that ought to end your program. And there is Ctrl+C and Ctrl+Break for an instant termination, regardless what your program is doing. You can get a notification for these with SetConsoleCtrlHandler() but you can't block it.

If the default behavior is dangerous and risk the health of a human then I'd strongly suggest you hire a consultant. And won't know who wrote this answer.

这篇关于如何以及为什么QuickEdit模式在命令提示符冻结应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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