aspose 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
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: 14445
    
  23

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 8 API documentation
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);
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Call exe file with parameters in JAVA