This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Run .bat file from java application  RSS feed

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody suggest on this??? I know how to run .exe using processbuilder...



Thanx in Advance
Sachin!!!
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can execute application from java using Runtime object. Find the sudo code below.
Runtime rtObj =Runtime.getRuntime()
rtObj.exec("appl.exe");
 
Ranch Hand
Posts: 824
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//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();
}

}
 
Sachin Dimble
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx Arun,Sunil for u r valuable suggestion.

Sachin!!!
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!