Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Is there an equivalent key-stroke for exiting a command prompt on Windows (launched via Start->Run : cmd) to the bash standby of Ctrl-d to prevent needing to type exit to leave the shell?

share|improve this question

4 Answers 4

up vote 10 down vote accepted

No. CtrlD on *nix generates a EOF, which various shells interpret as running exit. The equivalent for EOF on Windows is CtrlZ, but cmd.exe does not interpret this specially when typed at the prompt.

share|improve this answer
2  
With most modern shells, the terminal is not in canonical input mode when the shell is interactively accepting input, and Ctrl+D is in fact just an ordinary character and not an EOF special character. Shells bind Ctrl+D to a GNU Readline or ZLE action that exits (but only if the line editing buffer is empty) so the behaviour is mostly the same result. But Ctrl+D is not EOF with modern shells, just an ordinary control character. The behaviour when the editing buffer is not empty is markedly different to what happens with an EOF special character. –  JdeBP May 31 '11 at 22:28
2  
Indeed, the nearest Windows NT equivalent to what bash et al. are actually doing is a TCC/LE autoexecuting keyboard alias, such as this one, where the command interpreter (not the console) recognizes the ordinary keystroke combination ALT+F4 during line editing and executes the built-in exit command in response. –  JdeBP May 31 '11 at 22:36

You can use DOSKEY to create macros in CMD.exe.

To create a macro type:

DOSKEY [macroname]=[command(s)]

That way you can bind a key to another command.

Example:

DOSKEY e=exit

would bind e to the exit command, so when you input an e to the prompt it would be like you input an exit

I'm not sure if you can use CTRL-$n combinations as macros though

share|improve this answer
    
Most control characters work okay (except those already handled by the console, of course). But cmd just interprets them as normal commands, waiting for Enter to be pressed, so there is no advantage of aliasing Ctrl-Z versus just e or x. –  grawity Jan 21 '12 at 19:13

There is now an open source project called clink at http://code.google.com/p/clink/ - it brings Unix readline functionality to the Windows command prompt.

It supports most functionality including command-line editing, history search, tab completion along with completion scripts, etc. Well worth checking out, makes cmd suck much less. ;]

share|improve this answer

You can get the same effect with this AutoHotKey snippet:

; Close Command Prompt when pressing Ctrl+D
#IfWinActive, Command Prompt$
  ^d::
    ; First send ESC, in case we're in select mode.
    Send {Esc}{Esc}exit{Enter}
#IfWinActive
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.