Solved

getRuntime().exec() problem

Posted on 2010-08-30
4
386 Views
Last Modified: 2013-11-23
In the line below, filename is a String that is the path and filename of an excel file. This works (ie the file is displayed in Excel), except when there is a space in the path. How can this be fixed?

Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "start", filename });

Open in new window

0
Comment
Question by:allelopath
  • 2
4 Comments
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 300 total points
ID: 33559604
check this link (scroll down or search for "Path to executable with spaces in them")
http://www.rgagnon.com/javadetails/java-0014.html
0
 
LVL 16

Expert Comment

by:Valeri
ID: 33559772
Try this:
Runtime.getRuntime().exec(new String[] { "cmd.exe", "/c", "start", "\"" + filename + "\"" });
0
 
LVL 1

Author Comment

by:allelopath
ID: 33559817
From the link, this works:
String[] commands = {"cmd", "/c", "start", "\"DummyTitle\"",fileName};

That DummyTItle is necessary, doesn't work without it. What does it do?
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 200 total points
ID: 33560113
This Dummy title is needed only for windows. If start command sees a string it takes it as a title of the command window. That's way the dummy title is needed, otherwise the real filename is considered as a title of the command window.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Suggested Solutions

Title # Comments Views Activity
login jsp example 24 68
Which non-HTML GUI front end to use with Java? 3 24
Java: anonymous class 4 29
American Express @Work site and Java 4 30
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…
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 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 practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

830 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