• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

How to call EXE from JAVA  RSS feed

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Hi Peter,
Thanks for the Information.
 
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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() );
}
 
The happiness of your life depends upon the quality of your thoughts -Marcus Aurelius ... think about this tiny ad:
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!