Search code examples
emacselisp

How to open the native cmd.exe window in Emacs


I want to open a cmd.exe window with the project root directory as it's current directory.

Here is my elisp code:

(defun open-cmd-and-cd-to-project-root()
  (interactive)
  (projectile-mode t)
  (cd (projectile-get-project-root))
  (shell))

It opens a cmd shell in an Emacs buffer . But I want it opens a new native cmd.exe window running in Windows rather than a buffer running in Emacs. How can I do that?


Solution

  • Do this:

    (let ((proc (start-process "cmd" nil "cmd.exe" "/C" "start" "cmd.exe")))
      (set-process-query-on-exit-flag proc nil))
    

    The set-process-query-on-exit-flag to nil is so it won't bother on closing emacs (we can't kill it anyway).