I have a .bat file that passes in connection strings and password arguements to a java program. Any of these fields could have embedded percent signs. The values are entered by the client. I would like to programmatically search these fields and replace all % with %%. Below is an exmple where two arguments (uid and pwd) have embedded %. When the java program receives the arguments they are not as written in the dos batch file.
set uid="--uid=theb%renda"
set pwd="--pwd=pass%word1%234"
"%JAVA_HOME%" -classpath %CLASSPATH% javaprogram %uid% %pwd%
want to turn uid and pwd to this
set uid="--uid=theb%%renda"
set pwd="--pwd=pass%%word1%%234"
"%JAVA_HOME%" -classpath %CLASSPATH% javaprogram %uid% %pwd%
how to programmatically escape percent signs %
Moderator: DosItHelp
Re: how to programmatically escape percent signs %
Hi sage12,
you should use delayed expansion, too avoid any problems with special charaters.
But your main problem is a bit difficult.
I don't understand, who builds the lines
Are they build by another program and prepended to your batch file?
Or are they part of another batch file?
This way the set command will drop the percent signs.
But when the it's part of a config/user file, you could read that file via FOR/F without losing the percents.
you should use delayed expansion, too avoid any problems with special charaters.
Code: Select all
setlocal EnableDelayedExpansion
"%JAVA_HOME%" -classpath %CLASSPATH% javaprogram !uid! !pwd!
I don't understand, who builds the lines
Code: Select all
set uid="--uid=theb%renda"
set pwd="--pwd=pass%word1%234"
Or are they part of another batch file?
This way the set command will drop the percent signs.
But when the it's part of a config/user file, you could read that file via FOR/F without losing the percents.