22

I want to invoke:

"c:\(...)\devenv.com" foo.sln /build "Debug|Win32"

using cmd.exe. In my experience, cmd.exe either strips out the first pair of quotes (causing the executable to not be found) or the second pair of quotes (causing the pipe character to be misinterpreted). How do you pass a quoted pipe character to cmd.exe?

guerda
  • 21,229
  • 25
  • 89
  • 139
Gili
  • 76,473
  • 85
  • 341
  • 624

3 Answers3

31

You can either do it the way you are doing there, enclosing the string with the | in quotation marks.

Or you can escape it with the circumflex accent ^:

"c:\(...)\devenv.com" foo.sln /build Debug^|Win32

As a side note: Why are you building this with DevEnv instead of MSBuild?

Joey
  • 316,376
  • 76
  • 642
  • 652
  • DevEnv was always "good enough" and I was not familiar with MSBuild. I've got a cross-platform build system invoking DevEnv under the hood so I don't think I gain much by using MSBuild. Do I? – Gili Jul 29 '09 at 14:20
  • By the way, where is this escape character documented? – Gili Jul 29 '09 at 14:52
6

The caret (^) character is special shell characters to escape character for things like <, >, (, ), ...

cmd/c "echo Hello ^"  World"

Output

Hello " World
Ahmed Atia
  • 17,223
  • 24
  • 88
  • 129
6

Here's another solution (workaround?) I've found:

first, ensure an environment variable defines the pipe character, for example:
set PIPE="|"

later, run the command specifying the above defined environment variable name:
"c:\(...)\devenv.com" foo.sln /build Debug%PIPE%Win32

That does the job even if there are multiple wrappers between the caller and the callee. I'm now using it with a very long chain of wrappers: Python/Linux -> VirtualBox guest's executeProcess -> Cmd/Windows -> devenv.com

rdesgroppes
  • 616
  • 7
  • 9
  • This is the only way I got working to define a variable which I pass to a `powershell -c %variable%`. Neither `set variable=' ... | ...'` nor `set variable=" ... | ... "` nor any combination with `^|` with or without single or double quotes worked for me. The definition of the variable already gave an error. – TNT Dec 24 '18 at 08:34