I have a deployment script to which i have to pass LDAP password as cmd paramater.
actual password: foo\$ser"ver\\ 1
(contains three space characters: at the beginning, before 1
, and after 1
)
e.g
...bin>deployment.bat LDAPPassword= foo\$ser\"ver\\ 1
Note:There are spaces in the password as shown at the beginning.
The deployment.bat
calls a class to which the above parameter is passed as an argument.
The problem is that the class receives 2 distinct arguments:
args[0]= foo\$ser"ver\\ //The space after \\ is omitted
args[1]=1 //The space before and after 1 is omitted
How do I pass this password so that it is received as single string?
I have already tried quoting the password as
...bin>deployment.bat LDAPPassword=" foo\$ser"ver\\ 1 "
however it won't work.
To quote the full string you need to escape the quote so it is not seen as an ending quote.
And in the cases where the quote is already prefixed with a backslash, then you will also have to escape the backslash. So a password as
should be written as
For more information, this is the "usual" way of parsing arguments in windows.
EDITED - Just to document tests. Using this batch file (
test.cmd
)where
cmdline.exe
is obtained from this c codeand CmdLine.java is
Running
test.cmd " foo\$ser\"ver\ 1 "
the results areYou can't escape your password in any way.
As some combinations with quotes together with spaces can't be placed into one parameter.
Like this
"
(<space><quote><space>
) even if you add some quotes around, it's not possible, even if you quote the spaces and the quotes itself.Here is the best to double all quotes inside your password and enclose your password into quotes.
Then you can use all other characters are without any problems.
deployment.bat " foo\$ser\""ver\ 1 "
And in deployment.bat
You should use your password only with delayed expansion to avoid problems with special characterts.
For accessing command line parameters you could also look at
SO: How to receive even the strangest command line parameters?