日期:2014-05-16  浏览次数:20523 次

java 运行bat并获取返回结果
public void runbat(String timeFortmat) {   
        String cmd = "cmd /c C://" + timeFortmat + ".bat";   
        Runtime runtime = Runtime.getRuntime();   
        Process child = null;    
        try {   
            child = runtime.exec(cmd);   
            InputStream in = child.getInputStream();   
            String output = null;   
            int isSuccessful = 0;   
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));    
  
            output=bufferedReader.readLine();    
  
            while(output!= null){    
  
                System.out.println(output);    
  
                output=bufferedReader.readLine();    
  
            }    
  
               
            try {   
                //isSuccessful = child.waitFor();   
            } catch (Exception e) {   
                e.printStackTrace();   
            }    
  
        } catch (IOException ioe) {   
            ioe.printStackTrace();   
        }finally{   
            child.destroy();   
        }   
        System.out.println("------------>ok");   
    }