Correct quoting for cmd.exe for multiple arguments

Cmd

Cmd Problem Overview


I want to call

cmd /c "C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\devenv.com" mysolution.sln /build "release|win32"

Unfortunately this does not work, because I get the error: > 'C:\Program' is not recognized as an internal or external command, operable program or batch file.

As I understand, I need quoting for the spaces and quotes for the |, but I am only allowed to use the quotes once.

Any ideas how to quote this command line call correctly?

Cmd Solutions


Solution 1 - Cmd

Note the "" at the beginning and at the end!

Run a program and pass a Long Filename

cmd /c write.exe "c:\sample documents\sample.txt"

Spaces in Program Path

cmd /c ""c:\Program Files\Microsoft Office\Office\Winword.exe""

Spaces in Program Path + parameters

cmd /c ""c:\Program Files\demo.cmd"" Parameter1 Param2

Spaces in Program Path + parameters with spaces

cmd /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""

Launch Demo1 and then Launch Demo2

cmd /c ""c:\Program Files\demo1.cmd" & "c:\Program Files\demo2.cmd""

CMD.exe (Command Shell)

Solution 2 - Cmd

Spaces are used for separating Arguments. In your case C:\Program becomes argument. If your file path contains spaces then add Double quotation marks. Then cmd will recognize it as single argument.

Solution 3 - Cmd

Spaces are horrible in filenames or directory names.

The correct syntax for this is to include every directory name that includes spaces, in double quotes

cmd /c C:"Program Files""Microsoft Visual Studio 9.0"\Common7\IDE\devenv.com mysolution.sln /build "release|win32"

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionpyfexView Question on Stackoverflow
Solution 1 - Cmdmoskito-xView Answer on Stackoverflow
Solution 2 - CmdDigviJay PatilView Answer on Stackoverflow
Solution 3 - CmdAK65View Answer on Stackoverflow