0

After researching, I think I know the answer to this: no. But just in case I am missing something: Is there a way to globally suppress % escaping in a CMD file? Something like:

SETLOCAL NOESCAPE
MYAPP.EXE "%41%42%43%44"

So MYAPP.EXE sees the literal string:

"%41%42%43%44"

I know I can double up on the percent signs but was wondering if there is a setting that can be switched on and off.

Thanks.

Neil Weicher
  • 2,090
  • 6
  • 27
  • 45

1 Answers1

3

No, there is no setting that allows an executed batch line to treat a percent as a literal. Percent interpretation is an integral part of how the batch parser works - See https://stackoverflow.com/a/4095133/1012053 for more info.

If you want a percent literal within an executed batch script line, than it must be doubled.

I have thought of a method of embedding and executing a command containing un-escaped percent literals, but it is an ugly hack. You put the string literal in a "labeled" comment, use FINDSTR to extract the string literal, and process that value via FOR /F. You can use multiple labels to selectively get the string you need.

@echo off
::cmd1:myapp.exe "%41%42%43%44"
::cmd2:myapp.exe "%91%92%93%94"
for /f "tokens=1* delims=:" %%A in ('findstr "^::cmd1:" "%~f0"') do %%B
for /f "tokens=1* delims=:" %%A in ('findstr "^::cmd2:" "%~f0"') do %%B

I don't know about you, but I would rather simply escape the percents ;-)

Community
  • 1
  • 1
dbenham
  • 119,153
  • 25
  • 226
  • 353