Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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: 12759
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
Similar Threads
how to call an exe from an java application program
How to call an executable (.exe) from java
Executing Unix command in Java
Doubt Pls Help me