?
Solved

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

Posted on 2006-10-21
13
Medium Priority
?
1,263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 18 hours left to enroll

764 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