Reputation: 31724
I have this stupid unknown behavior coming up. In my application I need to start a Java process to execute some task's. So on doing below:
1a) String[] ls = {"cmd",
"/C",
"\"C:\\t e m p\\run time\\jre\\bin\\java.exe\"",
"-jar",
"Canon.jar"};
ProcessBuilder p = new ProcessBuilder(ls);
p.redirectErrorStream();
Process pp = p.start();
The above works perfectly. But if say full-path to Canon.jar
contains white-spaces then it doesn't work. Basically I need to add quotes
around the Canon.jar
path. i.e.
1b) String[] ls = {"cmd","/C",
"\"C:\\Prac\\t e m p\\run time\\jre\\bin\\java.exe\"","-jar",
"\"C:\\Prac\\t e m p\\Canon.jar\""};
The above still doesn't work even after including quotes. It says:
Ending 'C:\Users\Jatin\Documents\Prac\t' is not recognized as an internal or external command, operable program or batch file.
The biggest problem is, the below also does not work:
1c) String[] ls = {"cmd","/C",
"\"C:\\Prac\\t e m p\\run time\\jre\\bin\\java.exe\"","-jar",
"\"C:\\Prac\\temp\\Canon.jar\""};//contains no white space.
It still says same error. How on earth can it say it again when path to Canon.jar
contains no white spaces. Why does it say problem with java.exe
path when 1a
worked.
Upvotes: 3
Views: 300
Reputation: 123508
Do you really need the cmd
at all? Consider removing it.
ProcessBuilder p = new ProcessBuilder(new String[]{"C:\\Prac\\t e m p\\run time\\jre\\bin\\java.exe","-jar",
"C:\\Prac\\t e m p\\Canon.jar"};
Upvotes: 2