Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 196
  • Last Modified:

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
0
prasad2000
Asked:
prasad2000
  • 4
1 Solution
 
OviCommented:
public class AppRunner {
     public static void main(String[] args) {
          String app = "notepad";
    try {
         Process process = Runtime.getRuntime().exec(app);
    } catch(Exception e) {}
     }
}
0
 
OviCommented:
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
 
prasad2000Author Commented:
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
 
OviCommented:
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
 
OviCommented:
So, what about some points ?
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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