File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT / JFace and the fly likes Java: Runtime.exec( Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Java: Runtime.exec("cmd") want to run windows application" Watch "Java: Runtime.exec("cmd") want to run windows application" New topic
Author

Java: Runtime.exec("cmd") want to run windows application

Mary Smith
Greenhorn

Joined: Aug 16, 2001
Posts: 4
hi everyone, pls help...
I am currently writing a piece of GUI code using Swing on Windows 98 platform. I was wondering if a filepath is given (eg: C:\filename.doc), is it possible to launch a suitable application (Microsoft Word) automatically when a user click on the filepath?
I know one way of doing it is to use:
Runtime.exec("C:\Program Files\Microsoft Office\Office\winword.exe C:\filename.doc");
The problem I encounted is that, I need to find out the path of the .exe file (excel, powerpnt, etc) I need each time.
So, is there any other good suggestions that I could still make this work without touching any of the window registry database file?
Luong Nguyen
Ranch Hand

Joined: May 06, 2001
Posts: 31
Hi Mary,
I think you can use the following:
String cmd = "rundll32 url.dll, FileProtocolHandler " + "C:\\filename.doc";
Runtime.getRuntime().exec(cmd);
Regards.
Luong Nguyen
Ranch Hand

Joined: May 06, 2001
Posts: 31
Hi,
I almost forgot. The command "rundll32 url.dll, FileProtocolHandler " + "C:\\filename.doc" is unable to run on Windows 9x. So you can use the following command for Windows 9x: "start " + "C:\\filename.doc".
Anusha Jv
Greenhorn

Joined: Jul 26, 2001
Posts: 19
Mary,

Did u try this out.
It works for me!
Ben Wood
Ranch Hand

Joined: Aug 14, 2001
Posts: 342
Hi!
At last! I have been looking for a similar solution for launching a default web-browser for some time, and had to settle with the user configuring the path to the browser using my options dialog before it would work. Thanks to this forum, i now have developed the following class in my app which can be called using something like;
launchWinApp lwa = new launchWinApp("http://www.javaranch.com");
or
new launchWinApp("c:\myfile.doc");
and it seems to be working fine in Windows 2000, although I haven't tested it on NT, 95 or 98 - it doesn't bother me because I'm developing in-house for 2000 and the odd NT machine .

I'm only extending JFrame so I can have the icons on the message dialogs for continuity, so that stuff could be taken out if you didn't need the dialogs.
cheers, Ben.


SCJP 1.4, www.gsi3d.org.uk
russ wicks
Greenhorn

Joined: Sep 07, 2001
Posts: 3
Originally posted by Mary Smith:
hi everyone, pls help...
I am currently writing a piece of GUI code using Swing on Windows 98 platform. I was wondering if a filepath is given (eg: C:\filename.doc), is it possible to launch a suitable application (Microsoft Word) automatically when a user click on the filepath?
I know one way of doing it is to use:
Runtime.exec("C:\Program Files\Microsoft Office\Office\winword.exe C:\filename.doc");
The problem I encounted is that, I need to find out the path of the .exe file (excel, powerpnt, etc) I need each time.
So, is there any other good suggestions that I could still make this work without touching any of the window registry database file?


if you use the following code:
runtime.exec("cmd.exe /c start "+m_sPath);
where m_sPath is the full path to your file it will work.
With many .exe files in Program Files you can simply do:
runtime.exec("cmd.exe /c start "+ winword.exe);
I think some are held in the classpath or something. If they aren't you cant do it as you cant use file paths with spaces.
 
 
subject: Java: Runtime.exec("cmd") want to run windows application
 
Threads others viewed
Creating File object problem
how to find the full path of powerpoint.exe?
How to open MS Word from Java
Locating Microsoft Excel executable
Does POI require any office component on Server ?
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture