This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Call exe file with parameters in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Call exe file with parameters in JAVA" Watch "Call exe file with parameters in JAVA" New topic
Author

Call exe file with parameters in JAVA

Joshua Cloch
Ranch Hand

Joined: Apr 27, 2006
Posts: 95
Hello everyone!

In a DOS-based console,if I want to encypt a file "m",I just use an exe file named "crypt" followed by the file name which is going to be encrypt.The command is: crypt m.Then press Enter,that is all.

How can I do this in java? I know how to call an exe file in java,but how can I pass a parameters like file name to the exe file?

Thanks very much!


truehh@hotmail.com
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13884
    
  10

You say you already know how to call an exe in Java. That's with the Runtime.exec() method, right?

There are several overloaded versions of this method - there's one where you just supply the name of the exe, but there are also versions where you can supply parameters.

Look it up in the API documentation.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Joshua Cloch
Ranch Hand

Joined: Apr 27, 2006
Posts: 95
Thanks very much!
The solution is very simple:
sample:

String[] commands={"c:\\crypt.exe","c:\\counted.lic"};
Runtime.getRuntime().exec(commands);
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call exe file with parameters in JAVA
 
Similar Threads
How to call EXE from JAVA
JNI
calling a exe of fortran from java with a file as an input to the fortran exe
calling a fortran program from java
Communicate with legacy programme