Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call exe file with parameters in JAVA

 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15495
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Joshua Cloch
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks very much!
The solution is very simple:
sample:

String[] commands={"c:\\crypt.exe","c:\\counted.lic"};
Runtime.getRuntime().exec(commands);
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic