Java如何调用windows bat文件

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 151 收藏 0 点赞 0 评论 0

ava代码 
public static void main(String[] args) {    
    String path = "D:\public.bat";    
    Runtime run = Runtime.getRuntime();    
    try {    
        // run.exec("cmd /k shutdown -s -t 3600");    
        Process process = run.exec("cmd.exe /k start " + path);    
        InputStream in = process.getInputStream();      
        while (in.read() != -1) {    
            System.out.println(in.read());    
        }    
        in.close();    
        process.waitFor();    
    } catch (Exception e) {             
        e.printStackTrace();    
    }    
   
}   
public static void main(String[] args) {         String path = "D:\public.bat";         Runtime run = Runtime.getRuntime();         try {             // run.exec("cmd /k shutdown -s -t 3600");             Process process = run.exec("cmd.exe /k start " + path);             InputStream in = process.getInputStream();                 while (in.read() != -1) {                 System.out.println(in.read());             }             in.close();             process.waitFor();         } catch (Exception e) {                         e.printStackTrace();         }      }

评论列表
文章目录