Solved

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

Posted on 2006-10-21
13
1,249 Views
Last Modified: 2008-01-09
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
0
Comment
Question by:Edy1988
  • 4
  • 4
  • 2
  • +1
13 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17781438
What is the path
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17781442
You would generally use something like

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

Author Comment

by:Edy1988
ID: 17781448
C:\Program Files\....
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 

Author Comment

by:Edy1988
ID: 17781504
This path also crash, you need to have:

""C:\\Program Files\\Something\\Something.exe" -version", no?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17781514
If there are parameters then it would be

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

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17781532
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
 

Author Comment

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

Any ideas?
0
 
LVL 1

Expert Comment

by:dbrownell83
ID: 17782094
you probably need to \ the spaces too?
0
 
LVL 1

Expert Comment

by:dbrownell83
ID: 17782113
also, try adding file:/

"file:/C:\\gen\\currency\\";
0
 

Author Comment

by:Edy1988
ID: 17782718
Hi,

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

Thanks
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18073593
PAQed with points refunded (100)

Computer101
EE Admin
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
micro services vs rest web services 16 107
web services creation SOAP vs REST 5 42
Way to decrease size of apk file 9 70
jboss wildfly 10.1 10 96
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question