[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

getRuntime().exec() problem

Posted on 2010-08-30
4
Medium Priority
?
393 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:
Gurvinder Pal Singh earned 1200 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 800 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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
Suggested Courses
Course of the Month18 days, 19 hours left to enroll

834 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