Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Execute another program in Window

Posted on 2002-06-12
7
Medium Priority
?
214 Views
Last Modified: 2006-11-17
Im trying to open-up another program (say Ms Word) from a java program. What should i code?
0
Comment
Question by:Heliumyap
  • 3
  • 2
  • 2
7 Comments
 
LVL 35

Expert Comment

by:girionis
ID: 7072619
 You can use the Runtime class:

Runtime.getRuntime().exec("<the msword executable file>");

  Hope it helps.
0
 
LVL 35

Expert Comment

by:girionis
ID: 7072624
..or...

  Runtime rt = Runtime.getRuntime();
  Process proc = rt.exec("<ms word executable file>");

  Hope it helps.
0
 

Author Comment

by:Heliumyap
ID: 7072662
i got this error msg:<
Dde2Word.java:7: unreported exception java.io.IOException; must be caught or declared to be thrown
Process proc = rt.exec("winword.exe");
>
the error pointer point at the "exec".
my codes inside main are:
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("winword.exe");

whats wrong with it?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
Venci75 earned 400 total points
ID: 7072688
try this:
Process proc;
try {
Runtime rt = Runtime.getRuntime();
proc = rt.exec("winword.exe");
} catch (Exception e) {
System.out.println("Cannot run the prgram. Exception: " + e);
}
0
 

Author Comment

by:Heliumyap
ID: 7072709
Strange....Anyway, i got this error message just as i aspected:
Cannot run the prgram. Exception: java.io.IOException: CreateProcess: winword.exe error=2

BTW, im using KAWA IDE PRO as the compiler.
0
 
LVL 9

Expert Comment

by:Venci75
ID: 7072717
may be you should use this:
proc = rt.exec("c:\\Program Files\\...\\Winword.exe");

because the word direcototy probably is not in your system path variable
0
 

Author Comment

by:Heliumyap
ID: 7072741
hey!....i tried that before hand but it still give me an error. So putting Runtime class inside try catch will make everything work, right?
anyway, thanks for the help. really!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

885 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