• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Anshuman Johri
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34863
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thanks a lot Jeanne.
I got the answer.
Take care.
Cheers!
 
Ghulam Rashid
Ranch Hand
Posts: 278
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic