How to run a batch file/native application from Java?

Iryna Issayeva

Use Runtime.exec(String pathToBatchFile).

Here is the sample from my code.


void runServer() {
   String str = null;
   String cmdServer="E:/Server/server.bat";
   Runtime run = Runtime.getRuntime();
   Process process = null;
   try {
      process = run.exec(cmdServer);
      BufferedReader br = 
        new BufferedReader(
          new InputStreamReader(process.getInputStream()));
      while ( null != ( str = br.readLine() ) )
	System.out.println( str );
      br.close();
   }
   catch( java.io.IOException e ) {
      System.out.println(
        "Error while executing the process : " + e );
   }
}
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact