为什么 Windows 控制台会在一段时间后丢失命令行历史记录(向上箭头)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1241453/
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
Why do Windows consoles lose command-line history (up arrow) after a time?
提问by wsorenson
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.
这似乎是随机的:在我在 Windows Vista 上使用的任何控制台一段时间/使用一段时间后,我失去了使用命令行历史记录(或命令缓冲区,如果你喜欢...)的能力,并点击向上或向下箭头不再做任何事情,这意味着历史中基本上有 0 个项目可用。
I've seen this behavior in Cygwin, CMD, and PowerShell.
我在 Cygwin、CMD 和 PowerShell 中看到过这种行为。
Sometimes this behavior applies to processes running inside the console - Python, MySQL client, etc.
有时这种行为适用于在控制台内运行的进程——Python、MySQL 客户端等。
Is this an inherent problem in Windows? A setting somewhere? Are there other consoles that don't have this problem?
这是 Windows 的固有问题吗?某个地方的设置?有没有其他控制台没有这个问题?
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.
ps - 如果您认为这与编程无关,请查看有关编程工具的其他问题,例如,几乎所有标记为“eclipse”的内容都涉及如何使用 IDE 而不是为其编程。
回答by Maximus
Two ways, I think.
两种方式,我想。
1) Far Manageris 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.
1) Far Manager是一个不错的选择。即使您不需要它的全部功能(文件/存档管理、编辑器、大量插件、宏),您也可以将其用作 cmd、tcc、sh 或任何其他程序、shell 或命令处理器的包装器/执行器.
For example
例如
- take 3 files from distrib (Far2 or Far3): far.exe, fareng.lng and (optionally) fareng.hlp
- run "far.exe /w", press Ctrl+BCtrl+O
- type any command in command line: dir, set, notepad, putty, an so on...
- 从发行版(Far2 或 Far3)中获取 3 个文件:far.exe、fareng.lng 和(可选)fareng.hlp
- 运行“far.exe /w”,按 Ctrl+BCtrl+O
- 在命令行中输入任何命令:dir、set、notepad、putty 等等...
History will be preserved between sessions, you may access it by Alt+F8(press Ctrl+Alt+Fto switch history into filter mode).
历史将在会话之间保留,您可以通过Alt+F8(按Ctrl+Alt+F将历史切换到过滤模式)来访问它。
Far 2.0 stores history (and settings) in the registry.
Far 2.0 在注册表中存储历史记录(和设置)。
Far 3.0 stores history in SQLite database, and may be portable.
Far 3.0 将历史存储在 SQLite 数据库中,并且可以移植。
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...
此外,Far 可以自动完成历史记录或磁盘文件/路径中的命令。还有插件(YAC)可以从别名等自动完成......
2)I have found recently interesting project: Clink- Bringing Bash's powerful command line editing to Microsoft Windows' cmd.exe
2)我最近发现了一个有趣的项目:Clink- 将 Bash 强大的命令行编辑带到 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-Rand Ctrl-S).
- History expansion (e.g. !!, !, and !$).
- Scriptable completion using Lua.
- 来自 GNU 的 Readline 库的强大的类似 Bash 的行编辑。阅读有关 Readline 键盘快捷键的更多信息。
- 上级路径补全(TAB)。
- 从剪贴板粘贴 ( Ctrl-V)。
- 支持完成可执行文件/命令和环境变量。
- 撤消/重做(Ctrl-_或Ctrl-X, Ctrl-U)
- 改进的命令行历史记录。
- 跨会话持续。
- 可搜索(Ctrl-R和Ctrl-S)。
- 历史扩展(例如 !!、! 和 !$)。
- 使用 Lua 的脚本化完成。
It seems a young but budding project, so I had created an option for use it in my Console Emulator.
这似乎是一个年轻但崭露头角的项目,因此我创建了一个选项以在我的Console Emulator 中使用它。
回答by Steve Gilham
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.
Windows“DOS 框”中有历史缓冲区的最大大小 -- 左上角图标,右键单击,选择属性,您将看到命令历史的缓冲区大小默认为 50。
回答by maccullt
Check your Scroll Lockkey. DOH! I hit mine by accident so that up and down arrow just scrolled the window.
检查您的Scroll Lock键。哦!我不小心碰到了我的,所以向上和向下箭头只是滚动窗口。
回答by Shay Levy
In PowerShell you can control the maximum size of history via the MaximumHistoryCount automatic variable (default is 64)
在 PowerShell 中,您可以通过 MaximumHistoryCount 自动变量(默认为 64)控制历史记录的最大大小
PS > $MaximumHistoryCount
PS > $MaximumHistoryCount
回答by user1769064
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.
我多年来一直遇到这个问题。主要是在 bash shell 的命令行中使用 python。经过今天的一些实验,当这种情况第 1000 次(或多或少)再次发生时,我能够通过将 shell 的命令历史设置为缓冲区大小为 999 并将缓冲区数设置为 999(我选择了最大的每个可能的设置,除了我之前的设置(50/50)之外,任何设置都可能起作用)。要访问命令历史记录,请右键单击 shell 窗口的左上角,选择“属性”,然后选择“选项”选项卡。我不确定这些设置对 shell 性能的影响,但到目前为止似乎没有其他任何影响,并且命令行历史记录再次在以前无法使用的同一个 shell 中对我来说有效。
Admittedly, my answer involves 1 experiment that worked.
诚然,我的回答涉及 1 个有效的实验。
回答by EMBarbosa
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.
控制台中的所有历史记录都由Doskey提供。它也始终可用于所有基于字符的交互式程序(例如程序调试器或文件传输程序),并为其启动的每个程序维护一个命令历史缓冲区和宏。
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.
在 DOS 时代,人们可以记住执行后清除历史记录的软件。我不确定它们是错误、预期行为还是两者的混合。但是您可以在此链接的末尾看到一些 Doskey 错误。
I suggest anyone who get this problem to try Doskey command options and see if (s)he can correct it.
我建议遇到此问题的任何人尝试 Doskey 命令选项,看看他是否可以纠正它。
回答by Mae
If "suddenly" all history is gone, maybe a new cmd-shell starts? Test:
如果“突然”所有历史都消失了,也许会启动一个新的 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…
Of cause in this example you'l see the new cmd-Start but if you try out this:
当然,在这个例子中你会看到新的 cmd-Start 但如果你试试这个:
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!
但是一个新的 CMD-Shell 启动了。因此,在这种情况下,“退出”可能会有所帮助!
回答by jah
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.
我从未经历过这种情况,但我想知道是否按下了ALT+F7
根据 清除命令历史记录的组合键DOSKEY /?
可能是原因。