Solved

getRuntime().exec() problem

Posted on 2010-08-30
4
380 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

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 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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
The viewer will learn how to implement Singleton Design Pattern in Java.

867 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

22 Experts available now in Live!

Get 1:1 Help Now