How to include pipe symbol in argument in batch file from bash script?

I have a shell script that I want to execute this line:

qtvars.bat vsstart "qt.sln" /BUILD "Debug|Win32" 

This works fine (although I had to change qtvars.bat , but it is not). The problem is that I want the command to be executed in a variable: EDIT: This also will not work if I type it in bash. I used to print it in cmd.exe , which I hardly did for a fair comparison.

 command="qtvars.bat" args="vsstart" $command $args "qt.sln" /BUILD "Debug|Win32" 

Now he is choking on the pipe! I get this message:

 'Win32' is not recognized as an internal or external command, operable program or batch file. 

I tried a bunch of exit forms from quotes and / or pipes, all to no avail. Interestingly, it works when it is an executable file and not a batch file, for example:

 command="devenv.exe" args="" $command $args "qt.sln" /BUILD "Debug|Win32" 

Thanks for any ideas.

+6
cygwin batch-file
source share
5 answers

I know that you are "avoiding" the channel symbol in the batch file with the ^ symbol, so ...

echo ^ | Some text here ^ |

Will be displayed ...

| Some texts here

I do not know if this will help you? Maybe try adding each channel character with ^ and see what happens ?:-)

+7
source share

This is a classic double-shielding case where both bash and CMD.EXE should be instructed to ignore special | (pipe).

Try the following:

 $command $args "qt.sln" /BUILD '"Debug|Win32"' 

This will be equivalent to how you type in the CMD.EXE prompt:

 qtvars.bat vsstart qt.sln /BUILD "Debug|Win32" 

Using the above, you are essentially forcing double quotes to be sent to CMD.EXE (you select them instead of bash.) The most distant single quotes instruct bash not to interpret or touch in any way what is inside them; internal double quotes instruct CMD.EXE to ignore any special characters (in this case, in this case).

Alternatively, you can also try:

 $command $args "qt.sln" /BUILD 'Debug\|Win32' 

This should be equivalent to how you type in the CMD.EXE prompt:

 qtvars.bat vsstart qt.sln /BUILD Debug\|Win32 

Note the use of single quotes (!), Which ensure that bash will not interpret \ (and will instead pass it as is to CMD.EXE.)

+3
source share

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

first, make sure the environment variable defines the channel symbol, for example:
set PIPE="|"

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

This does the job, even if there are several wrappers between the caller and the called party. Now I use it with a very long wrapper chain: Python / Linux -> VirtualBox guest executeProcess -> Cmd / Windows -> devenv.com

(cross-reference to: How to pass a quoted string character to cmd.exe? )

+1
source share

The pipeline symbol in the Windows scripting language is reset using the caret (^). I just had to do it the other day. I know this is old, but I thought I would post what I found if others came across this, like me.

+1
source share

Interesting! What happens when running | ?

Do these actions?

  • echo "Debug | Win32"
  • echo "qt.sln" / BUILD 'Debug | Win32 '
0
source share

All Articles