• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I invoke an .exe application from my JAVA program?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Members,
I want to invoke an application from my JAVA program.
The application is an .exe file and i need to pass parameters to it.
The application supports command line invoking.
I want my JAVA program to do this.
Please tell me how it can be done.
It is urgent for my project.
Waiting for your answers,
Thanks
Anshuman
INDIA
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anshuman,
Welcome to JavaRanch!

Take a look at Runtime.exec(). This allows you to make operating system calls from your java app.
 
Anshuman Johri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Jeanne.
I got the answer.
Take care.
Cheers!
 
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.io.*;

class cmdtest
{
public static void main(String args[]) throws Exception
{
BufferedReader bufRead = cmdtest.executeCommand();
String str;
while((str = bufRead.readLine()) != null)
{
System.out.println("" + str);
}

}

public static BufferedReader executeCommand( ) throws IOException
{
String str;
Runtime rt=Runtime.getRuntime();
BufferedReader bufInp=null;
try
{
Process p=rt.exec("help");
Process p=rt.exec("ls -l");
bufInp=new BufferedReader ( new InputStreamReader ( p.getInputStream() ) );
}
catch ( IOException ioExc )
{
ioExc.printStackTrace();
System.out.println("IO Exception: " + ioExc.getMessage() );
}
return bufInp;
}
}

Probably this will help.

Rashid
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic