I have written code to customize the compile-command to use MSBuild.exe if a .vcxproj file is found in the current directory for c-mode files via a c-mode-common-hook. Since MSBuild is not in the path my code sets compile command so that it includes the full path and file name of MSBuild.exe. This is obtained from the Windows registry.

The final compile command is for example

"\"C:\\Program Files (x86)\\MSBuild\\12.0\\bin\\amd64\\MSBuild.exe\" \"JAWSCore.vcxproj\" /p:Configuration=Debug"

The problem is that when I do a M-x compile I get the following error.

'C:\Program' is not recognized as an internal or external command,
operable program or batch file.

Is there a way to resolve this issue or would I be better off modifying my code to simply add the directory containing MSBuild to the exec-path and then simply setting compile command to the following.

"MSBuild.exe JAWSCore.vcxproj /p:Configuration=Debug"
  • Try putting a backslash \ before each space (I see two).
    – nanny
    Mar 16, 2015 at 19:50
  • 1
    It would be really easier to modify the path using getenv / setenv. Or you could use MS DOS short names :). Something like "Progra~1" if memory serves. Also, for this particular directory, there should be an environment variable, iirc its %PROGRAMFILES(x86)%.
    – wvxvw
    Mar 17, 2015 at 8:05
  • This is what I ended up doing.
    – Ben Key
    Mar 17, 2015 at 18:21

2 Answers 2


This looks like a variant of Emacs bug #18745 (really a bug of Windows' CreateProcess() function and/or cmd.exe), apparently it applies to .exes when called via the shell. It works if you don't quote the second argument:

(concat (shell-quote-argument msbuild) " " proj-file " /p:Configuration=Debug")

Or use the short file name instead of quoting the exe:

(concat (w32-short-file-name msbuild) " " (shell-quote-argument proj-file) " /p:Configuration=Debug")

You need to quote the spaces. Replace <space> with \<space>.

  • The elisp code I use to set the compile command boils down to the following line of lisp code. {(setq ret (concat (shell-quote-argument msbuild) " " (shell-quote-argument proj-file) " /p:Configuration=Debug"))} How would I modify this line to achieve this result?
    – Ben Key
    Mar 16, 2015 at 20:42

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.