0

I'm trying to build a cmd interactive function in Emacs, which would open a Windows command prompt - exactly like Win+R cmd does. Within Emacs, it would be accessible with M-x cmd, and it would open the Windows terminal on the current folder.

The reason I want to build this function is that there are cases where the Emacs shell does not give the outputs properly (see this), and in these cases I'd like to open a Windows terminal quickly, and at the location I'm at.

I know how to get the current folder in Emacs, but I can't seem to find how to launch the Windows console from Emacs. call-process works for programs like firefox.exe or explorer.exe, yet when I try the following, nothing appears (it doesn't matter if I write the full path or not):

(call-process "cmd.exe")

TL;DR: So, what would be the command to launch, from Emacs, an external command prompt at a specific path?

0

1 Answer 1

0

I came up with the following, which works:

(defun cmd()
  "Open an external Windows cmd in the current directory"
  (interactive)
  (let ((default-directory
      (if (buffer-file-name)
               (file-name-directory (buffer-file-name))
               default-directory))))
    (call-process-shell-command "start cmd"))

The idea to use start cmd instead of cmd comes from this SO question: it's the standard way to open a new cmd from a runnning one, in Windows.
The idea to use call-process-shell-command comes from multiple tries and errors.

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