3
votes

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?

2
can you rephrase the question ? I do not understand the question. - alinsoar
@alinsoar: In gvim.exe, I can open a new cmd terminal window by execute the command :!cmd . How can I do that in Emacs? - TomCaps
first, I never used windows of bill gates, so I do not know windows. second. "open a new cmd terminal window by execute the command :!cmd" is not a correct expression, so I have to guess. Do you want to run a command using Meta-! ? - alinsoar
z_axis: I do not understand what he wants. I also supposed that he wants "M-!". - alinsoar
@alinsoar: In Ubuntu I can launch the real terminal by Meta-! gnome-terminal , but I can't launch the real terminal by Meta-! cmd on Windows. - TomCaps

2 Answers

6
votes

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).

1
votes

Depending on the system configuration, the start command will spin up a native terminal or explorer window.

I believe the choice is down to whether you allow multiple instances of the explorer shell (the file browser), but some other config might be involved (Local Group Policy, etc.)

M-! start

Your confusion stems from the fact that M-! creates an ad-hoc shell for executing commands by the default processor (cmd.exe, or rather cmdproxy.exe in this case), so starting a shell from a shell will not yield a separate terminal window.

start is a cmd.exe builtin, which opens a new shell window (again, subject to system configuration, as well as arguments passed to it).