【问题标题】:Why doesn't pressing the up arrow get the previous command in nested processes为什么按向上箭头不能在嵌套进程中获取上一个命令
【发布时间】:2021-08-05 09:46:01
【问题描述】:

在命令行上,我可以通过按向上/向下箭头键来检索以前的命令。但是,如果我将 CMD 嵌套到一定深度之外,这将不起作用。为什么会这样?有没有办法让它发挥作用?

要重现,打开 CMD 并运行:

Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\>cmd
Microsoft Windows [Version 10.0.19042.1110]
(c) Microsoft Corporation. All rights reserved.

C:\>echo lands
lands

C:\>rem Pressing up here doesn't bring back "echo lands"

更多上下文:

我的 Python discord.py 机器人中有一个 REPL,它使用内置 code 模块的 InteractiveConsole 类的子类,该类支持使用箭头键获取上一行(已自行测试)。我使用Pew 在正确的虚拟环境中运行我的机器人(使用pew in bot python bot.py)。

方向键不起作用。当我运行我的机器人时,任务管理器会显示 6 个额外的进程(原始 cmd.exe 和控制台窗口主机以外的进程):

pew     # Pew's executable on the PATH
python  # Pew's virtual environment's Python
python  # Global Python
cmd     # Pew does subprocess.run(..., shell=True)
python  # Bot's virtual environment's Python
python  # Global Python

为了确认重要的是嵌套进程的数量,我又尝试了两件事。首先,我在全球范围内安装了 Pew(使用 pip install pew)并使用 python -m pew ... 运行机器人。有 4 个额外的进程(3 个 Python 和 1 个 CMD),箭头键仍然不起作用。然后,我制作了一个不创建中间外壳的 Pew 分支,并使用它运行机器人。有 3 个额外的进程(所有 Python),箭头键在 REPL 中工作。

【问题讨论】:

    标签: windows terminal process


    【解决方案1】:

    我仍然不知道为什么会发生这种情况,但我使用了ConEmu,它不会遇到这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-04
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 2016-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多