1

I need to pass a single (quoted) parameter to an exe file with a single leading caret.
I tried this:

@echo off
setlocal
call :RunQuery "^one two"
goto wrapup
:RunQuery
call test.exe %1
:wrapup

This results in

"^^one two"

But I need it to be

"^one two"

I tried

%~1, "%~1" and ^"%~1^"

without success.

The last one appears to work with an echo but not when used with the exe file:

call test.exe ^"%~1^"

In this case test.exe still seems to get two carets.

Ray Hulha
  • 10,701
  • 5
  • 53
  • 53
  • 1
    You are [not the first to discover this](http://stackoverflow.com/search?q=batch+call+doubles+caret). –  Mar 01 '17 at 23:42
  • Thanks, the second [link](http://stackoverflow.com/questions/12655558/strange-behavior-with-special-characters-in-arguments-of-batch-functions/12656803#12656803) actually helped me understand it better – Ray Hulha Mar 02 '17 at 16:07

1 Answers1

2

Try setting it to a variable before parsing it:

@echo off
setlocal
call :RunQuery "^one two"
goto wrapup
:RunQuery
set "escape=%1"
echo %escape%
:wrapup

Outputs:

"^one two"

Sam Denty
  • 3,693
  • 3
  • 30
  • 43