3

I have the following appcmd to add an exception to IIS7's ISAPI and CGI restrictions. The exception I am adding should look like:

c:\perl\bin\perl.exe "%s" %s

Here is the command line:

appcmd set config -section:isapiCgiRestriction "-+[path='c:\perl\bin\perl.exe \"%s\" %s', allowed='true', description='Perl CGI']"

If execute this from the command line it does this correctly, however if I execute this inside a .cmd batch file the path gets mangled and ends up looking like:

c:\perl\bin\perl.exe "s

The trouble seems arise because I have to escape the quotation marks around the first %s perl.exe parameter. But why this should behave differently in a batch file is a bit of a puzzle.

Can anyone explain why this is happening?

1
  • Torn between SF and SO for this one.
    – Kev
    Sep 8, 2010 at 10:31

1 Answer 1

3

The problem is that the command processor reads your "%s" %s and finds two mathing % signs, so this makes a valid batch variable (namely %" %). And after expanding that into nothing, only your "s remains.

You can escape a single %-sign in your batch file by doubling it, like this:

c:\perl\bin\perl.exe "%%s" %%s
1
  • Thanks Frank. That had me scratching my head for ages.
    – Kev
    Sep 8, 2010 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.