Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a quoted pipe character to cmd.exe?

Tags:

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?

like image 460
Gili Avatar asked Jul 29 '09 13:07

Gili


People also ask

How do I use special characters in CMD?

If you need to use any of these characters as part of a command-line argument to be given to a program (for example, to have the find command search for the character >), you need to escape the character by placing a caret (^) symbol before it.

What is pipe symbol in CMD?

The | command is called a pipe. It is used to pipe, or transfer, the standard output from the command on its left into the standard input of the command on its right.

How do you escape quotes in CMD?

Escape every double quote " with a caret ^ . If you want other characters with special meaning to the Windows command shell (e.g., < , > , | , & ) to be interpreted as regular characters instead, then escape them with a caret, too.


2 Answers

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?

like image 135
Joey Avatar answered Sep 21 '22 16:09

Joey


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

cmd/c "echo Hello ^"  World" 

Output

Hello " World 
like image 34
Ahmed Atia Avatar answered Sep 19 '22 16:09

Ahmed Atia