Been scouring the internet for a couple days now trying to figure out the solution to my question with no luck. Hopefully someone here knows how to do this.

I'm currently trying to set up my EMACS to be able to run a .bat file on my Windows 7 machine through the "M-x shell" command. If I open up a shell and navigate to my directory and run BuildDTO.bat it works just fine. I've also got an odd kind of solution that runs the command but only opens the output of the command in a buffer once it's finished running. The code in my .emacs file is shown below:

(defun compile ()
  "Runs a quick compile on the code.  Note this is specific to this work environment."
    (shell-command "PATH_TO_BAT/BuildDTO.bat")))

Here I am binding the compile command to my "M-m":

(global-set-key (kbd "M-m") 'compile)

My issue is that I want to maven going through the steps of compiling. Going through "M-x shell" and running the DTO creates a nice scrolling buffer with the output of each step but the compile() function does not. Any suggestions about how I could get this work? I'm kind of new to EMACS so I apologize if this is a rather dumb question but I can't figure out the solution.


up vote 5 down vote accepted

Emacs already has a command for doing what you want called compile. So remove your custom function, restart emacs (this are needed to unload your definition of compile) and then do M-xcompileRETPATH_TO_BAT/BuildDTO.batRET

The advantage of using compile to run compilation is that it lists errors that occurred during compilation in form of clickable links which you can click to jump to directly to problematic file

If you do this particular action frequently you can do one of the following

1) Set the compile-command command on per directory basis using Directory variables, see this for an example of this

2) Write a custom command, some thing like this

(defun my-compile ()
  (compile "PATH_TO_BAT/BuildDTO.bat"))
(defun my-compile ()
  ;; Switch to `*shell*'
  ;; Goto last prompt, clear old input if any, and insert new one
  (goto-char (point-max))
  (insert "PATH_TO_BAT/BuildDTO.bat")
  ;; Execute

(global-set-key (kbd "M-m") 'my-compile)

Your Answer


By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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