Solved

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

Posted on 2001-06-06
5
186 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
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 …

695 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