为什么 Windows 控制台在一段时间后会丢失命令行历史记录(向上箭头)?
这似乎是随机的:在 Windows Vista 上使用任何控制台一段时间/使用一段时间后,我失去了使用命令行历史记录(或命令缓冲区,如果您愿意的话......)的能力,并且无法按向上或向下键arrow 不再执行任何操作,这意味着历史记录中基本上有 0 个可用项目。
我在 Cygwin、CMD 和 PowerShell 中看到过这种行为。
有时,此行为适用于在控制台内运行的进程 - Python、MySQL 客户端等。
这是 Windows 中的固有问题吗? 某个地方的设置? 还有其他控制台没有这个问题吗?
ps - 如果您认为这与编程无关,请参阅有关编程工具的其他问题,例如,几乎所有标记为“eclipse”的内容都涉及如何使用 IDE,而不是为其编程。
It seems random: after some amount of time / usage of any console I use on Windows Vista, I lose the ability to use the command-line history (or command buffer, if you prefer...), and hitting the up or down arrow no longer does anything at all, meaning there are essentially 0 items available in the history.
I've seen this behavior in Cygwin, CMD, and PowerShell.
Sometimes this behavior applies to processes running inside the console - Python, MySQL client, etc.
Is this an inherent problem in Windows? A setting somewhere? Are there other consoles that don't have this problem?
ps - if you think this is non-programming related, please see other questions regarding programming tools, for instance, nearly anything tagged "eclipse" which deal with how to use the IDE rather than programming for it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(10)
我认为有两种方式。
1) Far Manager 是 shell 的不错选择。 即使您不需要它的所有功能(文件/存档管理、编辑器、大量插件、宏),您也可以将其用作 cmd、tcc、sh 或任何其他程序、shell 或命令处理器的包装器/执行器。
例如,
历史记录将在会话之间保留,您可以通过 Alt+F8 访问它(按 Ctrl+Alt+F 将历史记录切换到过滤模式)。
Far 2.0 将历史记录(和设置)存储在注册表中。
Far 3.0将历史记录存储在SQLite数据库中,并且可以移植。
此外,Far 可以自动完成来自历史记录或磁盘中的文件/路径的命令。 还有一个插件(YAC)可以从别名自动完成等等...
2) 我最近发现了有趣的项目:Clink - 将 Bash 强大的命令行编辑功能引入 Microsoft Windows 的 cmd.exe
这似乎是一个年轻但正在萌芽的项目,因此我创建了一个在我的控制台模拟器中使用它的选项。
Two ways, I think.
1) Far Manager is a good choice for a shell. Even if you don't need it's all power (file/archive management, editor, huge number of plugins, macros), you can use it as a wrapper/executor for cmd, tcc, sh or any other program, shell or command processor.
For example
History will be preserved between sessions, you may access it by Alt+F8 (press Ctrl+Alt+F to switch history into filter mode).
Far 2.0 stores history (and settings) in the registry.
Far 3.0 stores history in SQLite database, and may be portable.
Also, Far can autocomplete commands from history or files/paths from disk. And there is plugin (YAC) which can autocomplete from aliases and so on...
2) I have found recently interesting project: Clink - Bringing Bash's powerful command line editing to Microsoft Windows' cmd.exe
It seems a young but budding project, so I had created an option for use it in my Console Emulator.
Windows“DOS 框”中的历史记录缓冲区有最大大小 - 左上角图标,右键单击,选择属性,您将看到命令历史记录默认情况下的缓冲区大小为 50。
There's a maximum size of history buffer in a windows "DOS box" -- Upper left icon, right click, select properties and you'll see the Command History has a buffer size of 50 by default.
检查您的Scroll Lock键。
卫生部! 我不小心撞到了我的,所以向上和向下箭头只是滚动了窗口。
Check your Scroll Lock key.
DOH! I hit mine by accident so that up and down arrow just scrolled the window.
在 PowerShell 中,您可以通过 MaximumHistoryCount 自动变量(默认为 64)控制历史记录的最大大小
。 $MaximumHistoryCount
In PowerShell you can control the maximum size of history via the MaximumHistoryCount automatic variable (default is 64)
PS > $MaximumHistoryCount
我多年来一直遇到这个问题。 主要是在 bash shell 中从命令行使用 python。 经过今天的一些实验,当这种情况再次发生第 1000 次(或多或少)时,我能够通过将 shell 的命令历史记录设置为缓冲区大小为 999 并将缓冲区数量设置为 999(我选择了最大的)来解决该问题每个可能的设置,除了我之前的设置(50/50)之外,任何设置都可能有效。 要访问命令历史记录,请右键单击 shell 窗口的左上角,选择“属性”,然后选择“选项”选项卡。 我不确定这些设置对 shell 性能的影响,但到目前为止似乎没有其他任何影响,并且命令行历史记录再次在以前无法工作的同一个 shell 中为我工作。我意识到这个答案是与 steve-gilham 的答案类似,但也许提供了更多背景信息。
诚然,我的回答涉及 1 个有效的实验。
I have encountered this issue for years. Mostly with python used from the command line in a bash shell. After some experimentation today when this re-occurred for the 1000th time (more or less) I was able to fix the issue by setting the Command History for the shell to have buffer size of 999 and Number of Buffers to 999 (I picked the largest possible setting for each, it's possible any setting would have worked other than what I was prior, which was 50/50). To access the Command history, right click in in the upper left corner of the shell window, select Properties, then the Options tab. I'm not sure the ramifications of these settings to performance of the shell, but thus far nothing else seems affected and command line history is once again working for me in the same shell it previously wasn't working in. I realize this answer is similar to the answer by steve-gilham, but perhaps gives a bit more background.
Admittedly, my answer involves 1 experiment that worked.
控制台中的所有历史记录均由 Doskey 提供。 它还始终可用于所有基于字符的交互式程序(例如程序调试器或文件传输程序),并为其启动的每个程序维护命令历史缓冲区和宏。
在DOS时代,人们可以记住执行后清除历史记录的软件。 我不确定它们是错误、预期行为还是两者的混合。 但一些 Doskey 错误是已知的,正如您在此链接末尾看到的那样。
我建议任何遇到此问题的人尝试 Doskey 命令选项,看看是否可以纠正它。
All history in console is provided by Doskey. It also is always available for all character-based, interactive programs (such as program debuggers or file transfer programs), and maintains a command history buffer and macros for each program that it starts.
In DOS era, one can remember softwares that after execution cleared the history. I'm not sure they were bugs, expected behavior, or the mix of two. But some Doskey bugs were know as you can see in the end of this link.
I suggest anyone who get this problem to try Doskey command options and see if (s)he can correct it.
如果“突然”所有历史记录都消失了,也许会启动一个新的 cmd-shell?
测试:
当然,在这个示例中,您会看到新的 cmd-Start,但是如果您尝试以下操作:
您看不到,
但是启动了一个新的 CMD-Shell。
所以“退出”在这种情况下可能会有所帮助!
If "suddenly" all history is gone, maybe a new cmd-shell starts?
Test:
Of cause in this example you'l see the new cmd-Start but if you try out this:
You don't see
But a new CMD-Shell was started.
So "exit" may help in this case!
我从未经历过这种情况,但我想知道是否按下组合键
ALT+F7
(根据DOSKEY /?
清除命令历史记录)可能是原因。I've never experienced this, but I wonder if pressing the key combination
ALT+F7
, which clears command history according toDOSKEY /?
, might be the cause.当我处于 Windows 10 上的 Rez 环境中时,这发生在我身上。
根据 @user1769064 的上面的答案将缓冲区设置为 999 并使用新环境重新启动 shell,问题就消失了。 可能还有比 999 更低的数字也可以使用,但还没有尝试过。
This happened to me when I'm in a Rez environment on Windows 10.
As per @user1769064 's answer above setting the buffers to 999 and restarting the shell with a new environment the issue went away. There's probably a lower number than 999 with which it works as well, but haven't tried it.
C:\
图标。C:\
icon.