读书人

java 运作bat并获取返回结果

发布时间: 2012-07-28 12:25:13 作者: rapoo

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");       } 

读书人网 >其他数据库

热点推荐