java 执行cmd代码

来源:互联网 发布:IC是什么软件 编辑:程序博客网 时间:2024/06/06 12:49

import java.io.IOException;

public   class  DExe{  
   public   static   void   runExecFile(String   execFile)   throws   IOException    
   {  
   try{  
   Runtime.getRuntime().exec(execFile);  
   }catch(Exception   ex){  
   throw   new   IOException(ex.getMessage());  
   }  
   }  
    
   public   static   void   runExecFile(String   execFile,boolean   waitFlag)   throws   IOException  
   {  
   try{  
   Process   proc   =   Runtime.getRuntime().exec(execFile);  
   System.out.println("test");  
   if   (waitFlag)  
   proc.waitFor();  
   int   exitVal   =   proc.exitValue();  
                           System.out.println("Process   exitValue:   "   +   exitVal);  
    
   }catch(Exception   ex){  
   throw   new   IOException(ex.getMessage());  
   }  
   }  
    
   public   static   void   main(String[]   args)  
   {  
   try{  
   runExecFile("exp   user/pwd@sid   file=d://test.dmp",true);  
   System.out.println("系统已启动");  
    
   }catch(Exception   ex){  
   System.err.println(ex.getMessage());  
   }  
   }  
   }