4

I've read a lot about the question but the answers I have found don't work completely.

I try 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);

As I have spaces in my path, I use String array to pass the arguments to the Process But ... it opens a DOS command window but doesn't launch my program, as if the parameters where ignored

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

Could someone give me some advice please ? Thank you.

2
  • actually you need to put an empty title: start,"","Path\\To\\file" Commented Feb 2, 2012 at 14:11
  • what is "/c" in this ? Commented Nov 6, 2017 at 5:54

2 Answers 2

5

Try adding quotes around the path by inserting escaped quotes in your string, as follows:

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

Notice the \" at the start and end of the path string.

Sign up to request clarification or add additional context in comments.

Comments

4

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

1 Comment

Thanks Arun, I removed the start argument and it works perfectly !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.