Solved

how to invoke an exe file thro a java program??

Posted on 2001-06-06
5
172 Views
Last Modified: 2010-04-16
am writing a java program which invokes an exe file present in my system.
can anyone help me to solve it.
one more question is how to pass parameters to the exe program.
thx in advance
0
Comment
Question by:prasad2000
  • 4
5 Comments
 
LVL 9

Accepted Solution

by:
Ovi earned 25 total points
ID: 6159258
public class AppRunner {
     public static void main(String[] args) {
          String app = "notepad";
    try {
         Process process = Runtime.getRuntime().exec(app);
    } catch(Exception e) {}
     }
}
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6159261
Thid is with parameters, and asume that AppRunner.java is in the same directory with the compiled file AppRunner.class.

public class AppRunner {
     public static void main(String[] args) {
          String app = "notepad AppRunner.java";
    try {
         Process process = Runtime.getRuntime().exec(app);
    } catch(Exception e) {}
     }
}

Just run "javac AppRunner.java" followed by "java AppRunner"
0
 
LVL 1

Author Comment

by:prasad2000
ID: 6162535
hi ovi
thx for the solution.
its working fine.

for ex if i want to run calc.exe file
public class AppRunner {
    public static void main(String[] args) {
         String app = "calc";
   try {
        Process process = Runtime.getRuntime().exec(app);
   } catch(Exception e) {}
    }
}
this opens calc.exe
but if i want to set some integer instead of 0 which is by default.
is it possible??if so how?
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6162758
I think not. If you run in the command line 'calc.exe 1' you will not get the 1 integer on the calculator input line. So the problem is at the calc.exe program which does not accept parameters.
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6163005
So, what about some points ?
0

Featured Post

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.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…

744 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

9 Experts available now in Live!

Get 1:1 Help Now