Link to home
Start Free TrialLog in
Avatar of Edy1988
Edy1988

asked on

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What is the path
You would generally use something like

path = "\"C:\\Program Files\\Something\\Something.exe\"";
Avatar of Edy1988
Edy1988

ASKER

C:\Program Files\....
Avatar of Edy1988

ASKER

This path also crash, you need to have:

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

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

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);
Avatar of Edy1988

ASKER

Tryed the path = "\"C:\\Program Files\\Something\\Something.exe -version\"";
It still cuts the path after the C:\Program

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

"file:/C:\\gen\\currency\\";
Avatar of Edy1988

ASKER

Hi,

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

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial