Solved

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

Posted on 2001-06-06
5
184 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
[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
  • 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

739 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