Is there any easy way to open the system command line interface (e.g., cmd in Windows) at the directory containing the current buffer (if any)? Note that M-x shell open a command line interface within emacs, hence does not answer the question. I also tried M-x shell-command cmd but this also open the command line interface within emacs.

  • What happens if you type ! on directory name and then cmd when prompted for the program to run? I cannot test this on Windows.
    – wvxvw
    Commented Jun 14, 2017 at 12:23
  • Thank you for your comment, I don't understand by what you mean to type ! on directory name and then cmd. Do you mean to do M-! then giving cmd?
    – Name
    Commented Jun 14, 2017 at 13:13
  • In dired buffer ! is bound to dired-do-shell-command, so pressing it would be similar to M-! except Emacs automatically sets some parameteres for the command invoked, such as "current directory".
    – wvxvw
    Commented Jun 14, 2017 at 14:29

1 Answer 1


You need to use start cmd to get a new terminal window. Use M-& (async-shell-command) to avoid blocking Emacs. This creates a useless *Async Shell Command* buffer, you can use the start-process-shell-command function to avoid this:

(start-process-shell-command (format "cmd(%s)" default-directory) nil "start cmd")
  • This gives the desired behaviour only if default-directory is not set, because in that case, Emacs seems to resort to using the directory of the buffer you are in. If, however, you did set default-directory, then the terminal will always open in that directory, neglecting the folder you are in. See my answer here if you want the behaviour to be "launch in current folder" even when you have set default-directory.
    – kotchwane
    Commented Apr 6, 2021 at 18:23
  • @kotchwane Yeah, Emacs generally considers the value of default-directory to be "the folder you are in", by definition. If you change default-directory in a file-visiting buffer, there are two plausible values for "folder you are in", but fixing that is IMO a separate question.
    – npostavs
    Commented Apr 6, 2021 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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