Send EOF when CTRL+D is pressed in CMD or PowerShell. (Alias for CTRL+Z) #19292

Open
opened 2026-01-31 06:39:12 +00:00 by claunia · 6 comments
Owner

Originally created by @daviewales on GitHub (Jan 30, 2023).

Description of the new feature/enhancement

Send EOF to Windows programs when CTRL+D is pressed.
Essentially, make CTRL+D an alias for CTRL+Z, to mirror the shortcut from Linux.

This would make exiting from cross-platform REPLs such as Python more consistent across platforms.
For example, on Linux I can exit a Python REPL with CTRL+D, but on Windows I have to use CTRL+Z, ENTER.
There was an issue requesting this functionality in the Python REPL itself, but it was closed as they didn't want to go against the OS norms.

Proposed technical implementation details (optional)

When a user presses CTRL+D in CMD or PowerShell, it should send the same signal EOF to the running program that is currently sent when CTRL+Z is pressed.

Originally created by @daviewales on GitHub (Jan 30, 2023). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> Send EOF to Windows programs when CTRL+D is pressed. Essentially, make CTRL+D an alias for CTRL+Z, to mirror the shortcut from Linux. This would make exiting from cross-platform REPLs such as Python more consistent across platforms. For example, on Linux I can exit a Python REPL with CTRL+D, but on Windows I have to use CTRL+Z, ENTER. There was an issue [requesting this functionality in the Python REPL](https://github.com/python/cpython/issues/63289) itself, but it was closed as they didn't want to go against the OS norms. # Proposed technical implementation details (optional) <!-- A clear and concise description of what you want to happen. --> When a user presses CTRL+D in CMD or PowerShell, it should send the same ~~signal~~ EOF to the running program that is currently sent when CTRL+Z is pressed.
claunia added the Issue-FeatureProduct-TerminalArea-Server labels 2026-01-31 06:39:12 +00:00
Author
Owner

@carlos-zamora commented on GitHub (Feb 1, 2023):

Unfortunately, CTRL+Z is baked into the console pretty deep. This seems possible but it's not something we'll be able to prioritize.
In the meantime, you can replace CTRL+Z with CTRL+D in your terminal's config by adding a sendInput action: https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#send-input

@carlos-zamora commented on GitHub (Feb 1, 2023): Unfortunately, CTRL+Z is baked into the console pretty deep. This seems possible but it's not something we'll be able to prioritize. In the meantime, you can replace CTRL+Z with CTRL+D in your terminal's config by adding a sendInput action: https://learn.microsoft.com/en-us/windows/terminal/customize-settings/actions#send-input
Author
Owner

@j0le commented on GitHub (Aug 21, 2025):

@daviewales be aware that on Linux CTRL+D doesn't generate a signal in the sense of signal(7) (like SIGINT, CTRL+C), but it forces the call to read (read(2)) to return 0 meaning EOF (End of File).

I guess a similar thing is happening on Windows with CTRL+Z, Enter: I guess, the ReadFile function returns 0 via the out parameter lpNumberOfBytesRead. Is this true? If yes, is this documented somewhere? If yes, where? If not, should I open another issue?

On Linux you can configure the terminal with the program stty(1). For example you can configure the key combo (the byte) that sends EOF. Search for “eof” on the man(ual) page.

On Windows you can program your own stty program, which calls Set- and GetConsoleMode(). But it can’t do as much as the orginal stty. For example it cannot configure, which key sends EOF. See documentation for what it can do.

PowerShell can be configured to exit on CTRL+D:

Set-PSReadlineKeyHandler -Key Ctrl+d -Function DeleteCharOrExit

(copied from some random website)

In CMD this cannot be configured.

@j0le commented on GitHub (Aug 21, 2025): @daviewales be aware that on Linux <kbd>CTRL</kbd>+<kbd>D</kbd> doesn't generate a signal in the sense of [signal(7)](https://www.man7.org/linux/man-pages/man7/signal.7.html) (like SIGINT, <kbd>CTRL</kbd>+<kbd>C</kbd>), but it forces the call to `read` ([read(2)](https://www.man7.org/linux/man-pages/man2/read.2.html)) to return 0 meaning EOF (End of File). I guess a similar thing is happening on Windows with <kbd>CTRL</kbd>+<kbd>Z</kbd>, <kbd>Enter</kbd>: I guess, the [`ReadFile`](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-readfile) function returns 0 via the out parameter `lpNumberOfBytesRead`. Is this true? If yes, is this documented somewhere? If yes, where? If not, should I open another issue? On Linux you can configure the terminal with the program [`stty`(1)](https://www.man7.org/linux/man-pages/man1/stty.1.html). For example you can configure the key combo (the byte) that sends EOF. Search for “eof” on the man(ual) page. On Windows you can program your own `stty` program, which calls [`Set`-](https://learn.microsoft.com/en-us/windows/console/setconsolemode) and [`GetConsoleMode()`](https://learn.microsoft.com/en-us/windows/console/getconsolemode). But it can’t do as much as the orginal `stty`. For example it cannot configure, which key sends EOF. See documentation for what it can do. PowerShell can be configured to exit on <kbd>CTRL</kbd>+<kbd>D</kbd>: ``` Set-PSReadlineKeyHandler -Key Ctrl+d -Function DeleteCharOrExit ``` (copied from some random website) In CMD this cannot be configured.
Author
Owner

@DHowett commented on GitHub (Aug 21, 2025):

Well, it looks like this isn't documented in the Console docs. I did some digging, though.

The CP/M 1.4 Interface Guide (PDF) mentions it:

End of text is given by the character control-z,

Given DOS's CP/M lineage, and Windows' DOS lineage, it adds up.

I'll try to scare up more authoritative documentation. There's probably a DOS manual somewhere that explains it.

@DHowett commented on GitHub (Aug 21, 2025): Well, it looks like this isn't documented in the Console docs. I did some digging, though. The [CP/M 1.4 Interface Guide (PDF)](http://www.bitsavers.org/pdf/digitalResearch/cpm/1.4/CPM_1.4_Interface_Guide_1978.pdf) mentions it: ``` End of text is given by the character control-z, ``` Given DOS's CP/M lineage, and Windows' DOS lineage, it adds up. I'll try to scare up more authoritative documentation. There's probably a DOS manual somewhere that explains it.
Author
Owner

@j0le commented on GitHub (Aug 21, 2025):

Wow! That’s an old document. Thanks for digging!

I really would like to see this in the Console docs or the docs of ReadFile. But I guess some more digging is necessary before making this a hard fact (by documenting it).

@j0le commented on GitHub (Aug 21, 2025): Wow! That’s an old document. Thanks for digging! I really would like to see this in the Console docs or the docs of ReadFile. But I guess some more digging is necessary before making this a hard fact (by documenting it).
Author
Owner

@j0le commented on GitHub (Aug 21, 2025):

By the way: Ctrl+D works in Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32 now. It doesn't work in Python 3.12.9 (main, Mar 24 2025, 05:59:42) [GCC UCRT Clang 20.1.1 64 bit (AMD64)] on win32. I couldn't find it in the Changelog by searching for "ctrl", "exit", "eof". The only thing I could find was https://github.com/python/cpython/issues/89459 , where they change the help message for quitting the REPL, but not the actual source code change, which enables Ctrl+D.

@j0le commented on GitHub (Aug 21, 2025): By the way: <kbd>Ctrl</kbd>+<kbd>D</kbd> works in `Python 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] on win32` now. It doesn't work in `Python 3.12.9 (main, Mar 24 2025, 05:59:42) [GCC UCRT Clang 20.1.1 64 bit (AMD64)] on win32`. I couldn't find it in the [Changelog](https://docs.python.org/3.13/whatsnew/changelog.html) by searching for "ctrl", "exit", "eof". The only thing I could find was https://github.com/python/cpython/issues/89459 , where they change the help message for quitting the REPL, but not the actual source code change, which enables <kbd>Ctrl</kbd>+<kbd>D</kbd>.
Author
Owner

@daviewales commented on GitHub (Aug 21, 2025):

@j0le, perhaps related to the new REPL in Python 3.13? See also: https://github.com/python/cpython/issues/111201.

@daviewales commented on GitHub (Aug 21, 2025): @j0le, perhaps related to the [new REPL in Python 3.13](https://docs.python.org/3/whatsnew/3.13.html#whatsnew313-better-interactive-interpreter)? See also: https://github.com/python/cpython/issues/111201.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19292