• Post Reply Bookmark Topic Watch Topic
  • New Topic

Execute Windows program from Java  RSS feed

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a Java standalone app which generates a HTML file and writes it out to the c: drive. I want to fire off the web browser like Internet Explorer passing the name of this file.
How do I execute a Windows based program from a Java app?
 
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think you can use applet.
 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//You'll need to change the path if it's different
String ie = "C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE";
//Assume your htm file is in C:
String html = "C:\\YourHTM.html";
String[] cmd = {ie, html};

Runtime.getRuntime().exec (cmd);
 
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can alternatively use exec to run rundll32.dll. Try exec with this string:

Now you don't have to know the path to IE, only the path to your file. And if somebody has NetScape as their default browser, that's what they'll get. Of course, that may either be good or bad depending on your requirements.
This technique will open any file with the application that is associated with the extension in Windows, so you can run it against word docs, excel spreadsheets, images, etc. You can also have http instead of file to open pages on the Internet.
 
Susilo Saja
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Stan,
I am interested in that dll stuff, can you give me a reference about that?
 
John Lee
Ranch Hand
Posts: 2545
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is a Windows DLL file?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just did a Google on rundll32 and Java and got a ton of hits. I'm not sure where to look for all the options on rundll32. For example, FileProtocolHandler is just one of many options. Maybe try Microsoft.com.
BTW: Forgot to mention since exec works just like a command-line, you can type this command in a MS-DOS prompt window for testing.
Often you can just type a filename like "foo.xls" and launch the appropriate program without the rundll32 part of the command. This is a cute shortcut instead of launching Excel and browsing to the file, but I wouldn't rely on it in an application.
 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can create an instance of RunTime class,and execute any process.
I don't know the exact api,but give it a try.
i hope this might works.
Ashish
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!