Solved

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

Posted on 2006-10-21
13
1,246 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now