Link to home
Start Free TrialLog in
Avatar of prasad2000
prasad2000

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Ovi
Ovi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ovi
Ovi

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"
Avatar of prasad2000

ASKER

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?
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.
So, what about some points ?