Solved

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

Posted on 2006-10-21
13
1,245 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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

13 Experts available now in Live!

Get 1:1 Help Now