为什么 Windows 控制台在一段时间后会丢失命令行历史记录(向上箭头)?

发布于 2024-07-30 13:49:51 字数 379 浏览 6 评论 0原文

这似乎是随机的:在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(10

鸠书 2024-08-06 13:49:51

我认为有两种方式。

1) Far Manager 是 shell 的不错选择。 即使您不需要它的所有功能(文件/存档管理、编辑器、大量插件、宏),您也可以将其用作 cmd、tcc、sh 或任何其他程序、shell 或命令处理器的包装器/执行器。

例如,

  • 从 distrib 中获取 3 个文件(Far2 或 Far3):far.exe、fareng.lng 和(可选)fareng.hlp
  • 运行“far.exe /w”,按 Ctrl+B Ctrl+O
  • 在命令行中输入任何命令:dir、set、notepad、putty 等...

历史记录将在会话之间保留,您可以通过 Alt+F8 访问它(按 Ctrl+Alt+F 将历史记录切换到过滤模式)。

Far 2.0 将历史记录(和设置)存储在注册表中。

Far 3.0将历史记录存储在SQLite数据库中,并且可以移植。

此外,Far 可以自动完成来自历史记录或磁盘中的文件/路径的命令。 还有一个插件(YAC)可以从别名自动完成等等...

2) 我最近发现了有趣的项目:Clink - 将 Bash 强大的命令行编辑功能引入 Microsoft Windows 的 cmd.exe

  • 来自 GNU Readline 库的类似 Bash 的强大行编辑功能。 了解有关 Readline 键盘快捷键的更多信息。
  • 高级路径补全 (TAB)。
  • 从剪贴板粘贴 (Ctrl-V)。
  • 支持可执行文件/命令和环境变量的完成。
  • 撤消/重做(Ctrl-_Ctrl-XCtrl-U
  • 改进了命令行历史记录。
    • 跨会话持续存在。
    • 可搜索(Ctrl-RCtrl-S)。
    • 历史扩展(例如!!、! 和 !$)。
  • 使用 Lua 进行脚本化补全。

这似乎是一个年轻但正在萌芽的项目,因此我创建了一个在我的控制台模拟器中使用它的选项。

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

  • take 3 files from distrib (Far2 or Far3): far.exe, fareng.lng and (optionally) fareng.hlp
  • run "far.exe /w", press Ctrl+B Ctrl+O
  • type any command in command line: dir, set, notepad, putty, an so on...

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

  • Powerful Bash-like line editing from GNU's Readline library. Read more on Readline's keyboard shortcuts.
  • Superior path completion (TAB).
  • Paste from clipboard (Ctrl-V).
  • Support for the completion of executables/commands, and environment variables.
  • Undo/Redo (Ctrl-_ or Ctrl-X, Ctrl-U)
  • Improved command line history.
    • Persists across sessions.
    • Searchable (Ctrl-R and Ctrl-S).
    • History expansion (e.g. !!, !, and !$).
  • Scriptable completion using Lua.

It seems a young but budding project, so I had created an option for use it in my Console Emulator.

羁〃客ぐ 2024-08-06 13:49:51

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.

惟欲睡 2024-08-06 13:49:51

检查您的Scroll Lock键。
卫生部! 我不小心撞到了我的,所以向上和向下箭头只是滚动了窗口。

Check your Scroll Lock key.
DOH! I hit mine by accident so that up and down arrow just scrolled the window.

幸福还没到 2024-08-06 13:49:51

在 PowerShell 中,您可以通过 MaximumHistoryCount 自动变量(默认为 64)控制历史记录的最大大小

。 $MaximumHistoryCount

In PowerShell you can control the maximum size of history via the MaximumHistoryCount automatic variable (default is 64)

PS > $MaximumHistoryCount

旧城空念 2024-08-06 13:49:51

我多年来一直遇到这个问题。 主要是在 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.

涙—继续流 2024-08-06 13:49:51

控制台中的所有历史记录均由 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.

ら栖息 2024-08-06 13:49:51

如果“突然”所有历史记录都消失了,也许会启动一个新的 cmd-shell?
测试:

C:\Users\Guest\>doskey /history
 …long history…
C:\Users\Guest\>cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Guest\>doskey /history
 …no history…
C:\Users\Guest\>exit
C:\Users\Guest\>doskey /history
 …old long history…

当然,在这个示例中,您会看到新的 cmd-Start,但是如果您尝试以下操作:

doskey /history
  …history list…
cmd echo /k
doskey /history
  …no list !

您看不到,

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

但是启动了一个新的 CMD-Shell。
所以“退出”在这种情况下可能会有所帮助!

If "suddenly" all history is gone, maybe a new cmd-shell starts?
Test:

C:\Users\Guest\>doskey /history
 …long history…
C:\Users\Guest\>cmd
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.
C:\Users\Guest\>doskey /history
 …no history…
C:\Users\Guest\>exit
C:\Users\Guest\>doskey /history
 …old long history…

Of cause in this example you'l see the new cmd-Start but if you try out this:

doskey /history
  …history list…
cmd echo /k
doskey /history
  …no list !

You don't see

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

But a new CMD-Shell was started.
So "exit" may help in this case!

风启觞 2024-08-06 13:49:51

我从未经历过这种情况,但我想知道是否按下组合键ALT+F7(根据DOSKEY /?清除命令历史记录)可能是原因。

I've never experienced this, but I wonder if pressing the key combination ALT+F7, which clears command history according to DOSKEY /?, might be the cause.

清君侧 2024-08-06 13:49:51

当我处于 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.

删除会话 2024-08-06 13:49:51
  1. 右键单击 Windows 命令提示符左上角的 C:\ 图标。
  2. 选择属性
  3. 在“选项”选项卡中,找到“命令历史记录”设置
  4. 将缓冲区大小更改为 999
  5. 关闭终端并再次重新启动
  1. right-click on the top-left corner of the Windows Command Prompt on the C:\ icon.
  2. Choose Properties
  3. In the Options tab, find Command History setting
  4. Change the Buffer size to 999
  5. Close the terminal and relaunch it again
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文