I am trying to start a Java command line tool in its own cmd.exe window from Java. I use ProcessBuilder to start the following:
cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe"
This works. This also works:
cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe" -version
But when I try to run the following
cmd.exe /k "C:\Program Files (x86)\JavaSoft\jre\1.5.0_07\bin\java.exe" "test a"
I get an error saying it can't find "C:\Program". I expected to get an exception from java.exe. I need to be able to use quotation marks in some of the arguments. Is there any way to do this?
If you have control over where your JDK is installed, its a good idea to install it in a location that does not contain spaces. "Program Files" is the default location on Windows but it almost always leads to problems.
Try following:
You could try to use the old DOS trick for this one. Refer to Program Files as progra~1. This usually gets me around the problem.
From "cmd /?":
Okay, that explains why it doesn't work if there are more than two quotes. But that doesn't explain how exactly to solve the problem. Thankfully, Google has the answer: