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?

link|improve this question

feedback

2 Answers

up vote 5 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.

link|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
feedback

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

link|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 at 19:13
feedback

Your Answer

 
or
required, but never shown

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