Title: REPL history is broken when python is invoked with cmd /c
Type: behavior Stage: resolved
Components: Windows Versions: Python 3.7
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, paul.moore, steve.dower, tim.golden, zach.ware, 零欸特
Priority: normal Keywords:

Created on 2018-11-12 13:23 by 零欸特, last changed 2018-11-29 22:03 by eryksun. This issue is now closed.

Messages (2)
msg329729 - (view) Author: 零欸特 (零欸特) Date: 2018-11-12 13:23
Windows 7 x64
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)]

Steps to reproduce:

1. Create a script:
    from subprocess import run
    run(["cmd.exe", "/c", "python"])
    run("python", shell=True)
2. Run the script.

Actual result:

The script will invoke Python REPL 3 times. The first and the third REPL don't save the command history. Pressing up/down arrows would clear the entire line. Pressing F7 has no effect.

The second REPL works fine.

Expected result:

Command history should work in all instances.
msg330730 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-11-29 22:03
The Windows console has a fixed number of history buffers. In Windows 7 the default maximum is four history buffers. In this case, if we run a script via cmd.exe -> py.exe -> python.exe, then only one history buffer remains for a child process. As you've observed, no history buffer is available for the fifth process if we run cmd.exe -> python.exe. 

You can increase the default maximum in the console's Alt+Space+D defaults dialog, under "Command History" -> "Number of Buffers". This corresponds to the "NumberOfHistoryBuffers" value in the registry key "HKCU\Console". 

You can increase the maximum for the current window in the console's Alt+Space+P properties dialog. If the current console was allocated by an application that was launched from a shortcut (i.e. a .LNK file), this property gets persisted in the shortcut itself. Otherwise it gets persisted in a registry key under "HKCU\Console" that's named for the startup window title. If no title was specified, the default title is the path to the executable, with backslashes replaced by underscore and the Windows directory as %SystemRoot%. For example, if you run cmd.exe from the Win+R run dialog, its console properties are stored in the registry key "HKCU\Console\%SystemRoot%_system32_cmd.exe".
Date User Action Args
2018-11-29 22:03:56eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg330730

resolution: not a bug
stage: resolved
2018-11-12 13:23:21零欸特create