3

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.

3
  • 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
    Jun 14 '17 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
    Jun 14 '17 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
    Jun 14 '17 at 14:29
4

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")
2
  • 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
    Apr 6 '21 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
    Apr 6 '21 at 18:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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