How to send Windows path (With spaces) as parameters to Runtime.exec with Java 1.5?

Hi,

In Java 1.4 when I needed to send to Runtime.exec a parameter with spaces (Path under 'Program Files') I would just wrap it with:

String quotes= "\"";

and put quotes before and after it.

In Java 1.5 it adds to the string \" and not just " as I wanted, so how do I add " at the beginning and at the end?

Thanks
Eyal
Edy1988Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Computer101Connect With a Mentor Commented:
PAQed with points refunded (100)

Computer101
EE Admin
0
 
CEHJCommented:
What is the path
0
 
CEHJCommented:
You would generally use something like

path = "\"C:\\Program Files\\Something\\Something.exe\"";
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

 
Edy1988Author Commented:
C:\Program Files\....
0
 
Edy1988Author Commented:
This path also crash, you need to have:

""C:\\Program Files\\Something\\Something.exe" -version", no?
0
 
CEHJCommented:
If there are parameters then it would be

path = "\"C:\\Program Files\\Something\\Something.exe -version\"";

0
 
CEHJCommented:
You'd be better off doing it more like this though:

List<String> args = new ArrayList<String>(2);
 args.add("C:\\Program Files\\Something\\Something.exe");
 args.add("-version");
 ProcessBuilder pb = new ProcessBuilder(args);
0
 
Edy1988Author Commented:
Tryed the path = "\"C:\\Program Files\\Something\\Something.exe -version\"";
It still cuts the path after the C:\Program

Any ideas?
0
 
dbrownell83Commented:
you probably need to \ the spaces too?
0
 
dbrownell83Commented:
also, try adding file:/

"file:/C:\\gen\\currency\\";
0
 
Edy1988Author Commented:
Hi,

The problem was the parameters "cmd.exe /C" before the command, now it works.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.