Execute another program in Window

Im trying to open-up another program (say Ms Word) from a java program. What should i code?
HeliumyapAsked:
Who is Participating?
 
Venci75Connect With a Mentor Commented:
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
 
girionisCommented:
 You can use the Runtime class:

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

  Hope it helps.
0
 
girionisCommented:
..or...

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

  Hope it helps.
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
HeliumyapAuthor Commented:
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
 
HeliumyapAuthor Commented:
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
 
Venci75Commented:
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
 
HeliumyapAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.