Solved

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

Posted on 2006-10-21
13
1,257 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
Industry Leaders: 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

Technology Partners: 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!

Question has a verified solution.

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

Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

724 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