Ignore question mark in .bat scripts

The thing is, I need to pass one parameter with question marks to it in a .bat batch file. If I use a question mark, the parameter fails. How can I solve this?

I am having problems with this line:

script.bat /n"output.owl" /r"http://www.address.com/blog/?feed=rss2"

      

Symbol

=

could be a problem too.

0


a source to share


2 answers


I suspect the problem is that the original batch file uses a for loop to process command line parameters, and the question mark is used for the wildcard filename extension.

> type fortest.bat
@echo off
for %%a in (%*) do (
   echo arg is %%a
)
> fortest a b c/?d
arg is a
arg is b

      



Using positional parameters% 1 and% 2 eliminates wildcard expansion done in a for ... (% *) loop. The shift operator avoids the wildcard also if an unknown number of parameters need to be processed.

> type shifttest.bat
@echo off
:loop
    if "x%1" == "x" goto :eof
    echo arg is %1
    shift /1
    goto :loop
> shifttest a b c/?d
arg is a
arg is b
arg is c/?d

      

+2


a source


Can you always just trap? in your batch file and display an appropriate message to the user.



This is a question to help you that has already been asked.

0


a source







All Articles