how to programmatically escape percent signs %
Posted: 11 Sep 2018 04:09
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%
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%