Java: Running / cmd / c start path-with-spaces \ program.exe

I read a lot about the question, but the answers I found do not work fully.

I am trying to run this code:

String[] args = {"cmd","/c","start","C:\\Program Files\\XML Marker\\xmlmarker.exe"}; Runtime rt = Runtime.getRuntime(); ProcessBuilder pb = new ProcessBuilder(args); Process pr = pb.start(); //Process pr = rt.exec(args); 

Since I have spaces in my path, I use the String array to pass arguments to Process But ... it opens a DOS command window, but does not run my program, as if the parameters were ignored

I tried with rt.exec (args) and pb.start () ... same result

Can someone give me some advice please? Thanks.

+4
source share
2 answers

No need to have a "start" and "cmd" at the same time. You can safely take out the "start". If you use a parameter enclosed in quotation marks with the "start" command, it treats it as the title for a new command window.

+4
source

Try adding quotes around the path by inserting escape quotes into your string, as follows:

 String[] args = {"cmd","/c","start","\"C:\\Program Files\\XML Marker\\xmlmarker.exe\""}; 

Pay attention to \" at the beginning and end of the path line.

+5
source

All Articles