2

I have a bat-file in which I'm trying to pass the JVM a list of non proxy hosts via "-Dhttp.nonProxyHosts". The file already contains a list of arguments and if I try to just add the one in question like this:

set "JAVA_OPTS=-Xms64M -Xmx1024M -XX:MaxPermSize=256M"
...
set "JAVA_OPTS=%JAVA_OPTS% -Dhttp.nonProxyHosts=*.company.com|localhost|127.0.0.1"

Windows tells me "command 'localhost' not found".

And if I try to escape it like

set "JAVA_OPTS=%JAVA_OPTS% -Dhttp.nonProxyHosts=*.company.com^|localhost^|127.0.0.1"

The result is pretty much the same, so how DO I pass this list correctly?

Cheers Simon

1 Answer 1

2

I suppose the problem isn't the SET, it's later when you use the JAVA_OPTS variable.

The best way is to use delayed expansion here, as it's ignore special characters at all.

setlocal EnableDelayedExpansion
set "JAVA_OPTS=-Xms64M -Xmx1024M -XX:MaxPermSize=256M"
set "JAVA_OPTS=%JAVA_OPTS% -Dhttp.nonProxyHosts=*.company.com|localhost|127.0.0.1"

java.exe !JAVA_OPTS!
0

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.