RuntimeTest


/*
 * 【JAVA中執行bat】

>test.bat  
haha  
exit  99  

>RuntimeTest.java
 *
 *
 *
 */
public  class  RuntimeTest  {  

           public  static  void  main(String[]  args)  {  
                       try  {  
                                   Process  process=Runtime.getRuntime().exec("test.bat");  
                                   StreamGobbler  errorGobbler  =  new  StreamGobbler(process.getErrorStream(),  "ERROR");                          
                 
                           //  kick  off  stderr  
                           errorGobbler.start();  
                             
                           StreamGobbler  outGobbler  =  new  StreamGobbler(process.getInputStream(),  "STDOUT");  
                           //  kick  off  stdout  
                           outGobbler.start();  
                             
                                   process.waitFor();  
                                   System.out.println(process.exitValue());  
                       }  catch(Exception  e)  {}              
           }  
}  

 

發佈了50 篇原創文章 · 獲贊 1 · 訪問量 5萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章