jQuery in Action, 2nd edition
The moose likes Java in General and the fly likes How To Run .bat  file from java application Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How To Run .bat  file from java application" Watch "How To Run .bat  file from java application" New topic
Author

How To Run .bat file from java application

Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Can anybody suggest on this??? I know how to run .exe using processbuilder...



Thanx in Advance
Sachin!!!
Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
You can execute application from java using Runtime object. Find the sudo code below.
Runtime rtObj =Runtime.getRuntime()
rtObj.exec("appl.exe");


Sharing is learning
Sunil Kumar Gupta
Ranch Hand

Joined: Aug 26, 2005
Posts: 824
//java source
import java.io.*;

public class MyRun
{



public MyRun()
{


Runtime runtime = Runtime.getRuntime();
String[] cmd =
{"cmd","/c","abc.bat"};
try{

Process p =runtime.exec(cmd);

BufferedReader b =new BufferedReader(new
InputStreamReader(p.getInputStream()));
String line=null;
while( (line=b.readLine())!=null)
{

System.out.println(line);

}

}
catch(Exception e)
{

e.printStackTrace();
}


}




public static void main(String args[])
{

MyRun r =new MyRun();
}

}


Lack of will power has caused more failure than lack of intelligence or ability.
My Blog | Red5 Resources | Technology Update | Daily Technology Tips
Sachin Dimble
Ranch Hand

Joined: Dec 07, 2005
Posts: 100
Thanx Arun,Sunil for u r valuable suggestion.

Sachin!!!
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: How To Run .bat file from java application
 
Similar Threads
Servlets
JSP
I've bought Sybex Java 2 Certification Virtual Trainer
how to execute wml
Whyis the error "Exception in thread "main" java.lang.NoSuchMethodError: main"?