• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to call EXE from JAVA

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Buddies,
I have an Exe File, want to call that in my java application can anyone tell me how to do it.
narayana
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.
Take a look at the java.lang.Runtime.exec() method:
http://java.sun.com/j2se/1.4.1/docs/api/java/lang/Runtime.html
/Peter
 
narayana murthy pedapudi
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for the Information.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;
public class ExeCommand {
public static void main(String args[]) {
try {
Process p = Runtime.getRuntime().exec("path_of_your_exe_file");
p.waitFor();
}
catch(IOException e){}
catch(InterruptedException e){}
}
}
[ August 01, 2003: Message edited by: Tiago Fernandez ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
Bill
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
try
{
Process p1 = runtime.exec("cmd /c Dir");
InputStream is = p1.getInputStream();
int i = 0;
while( (i = is.read() ) != -1)
{
System.out.print((char)i);
}

}
catch(IOException ioException)
{
System.out.println(ioException.getMessage() );
}
reply
    Bookmark Topic Watch Topic
  • New Topic