?
Solved

Execute another program in Window

Posted on 2002-06-12
7
Medium Priority
?
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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 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:
Suggested Courses

718 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