• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Execute another program in Window

Im trying to open-up another program (say Ms Word) from a java program. What should i code?
0
Heliumyap
Asked:
Heliumyap
  • 3
  • 2
  • 2
1 Solution
 
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
 
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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
Venci75Commented:
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
 
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

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now