Solved

Execute another program in Window

Posted on 2002-06-12
7
199 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 9

Accepted Solution

by:
Venci75 earned 100 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

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…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now