• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Mary Smith
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mary,

Did u try this out.
It works for me!
 
Ben Wood
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
russ wicks
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!