Solved

getRuntime().exec() problem

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 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 tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

757 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

20 Experts available now in Live!

Get 1:1 Help Now