• Post Reply Bookmark Topic Watch Topic
  • New Topic

How To Run .bat file from java application  RSS feed

 
Sachin Dimble
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!!!
 
Arun Boraiah
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");
 
Sunil Kumar Gupta
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!!!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!