File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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: 14117
    
  16

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);
 
jQuery in Action, 2nd edition
 
subject: Call exe file with parameters in JAVA