File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes How to call EXE from JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to call EXE from JAVA" Watch "How to call EXE from JAVA" New topic

How to call EXE from JAVA

narayana murthy pedapudi
Ranch Hand

Joined: Jul 23, 2003
Posts: 42
Hi Buddies,
I have an Exe File, want to call that in my java application can anyone tell me how to do it.
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
Take a look at the java.lang.Runtime.exec() method:
narayana murthy pedapudi
Ranch Hand

Joined: Jul 23, 2003
Posts: 42
Hi Peter,
Thanks for the Information.
Tiago Fernandez
Ranch Hand

Joined: May 16, 2003
Posts: 167
public class ExeCommand {
public static void main(String args[]) {
try {
Process p = Runtime.getRuntime().exec("path_of_your_exe_file");
catch(IOException e){}
catch(InterruptedException e){}
[ August 01, 2003: Message edited by: Tiago Fernandez ]

Tiago Fernandez
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13037
Tiago - it is not quite that simple. IF the application writes anything to stdout or stderr you need to provide for reading those streams or you will get strange behavior.
VIJAY Yadlapati
Ranch Hand

Joined: Aug 04, 2003
Posts: 175
Use java.lang.Runtime.exec() for executing external commands. If you are expecting any output from that application, use InputStream on that created Process.
Here is the sample code for DIR
Runtime runtime = Runtime.getRuntime();
Process p1 = runtime.exec("cmd /c Dir");
InputStream is = p1.getInputStream();
int i = 0;
while( (i = ) != -1)

catch(IOException ioException)
System.out.println(ioException.getMessage() );
I agree. Here's the link:
subject: How to call EXE from JAVA
jQuery in Action, 3rd edition