源代码:

01 class ExecCmd { 

02     public static void main(String args[]) { 

03         Runtime run = Runtime.getRuntime(); 

04         Process process = null; 

05         try { 

06             process = run.exec("notepad"); // 执行cmd命令 

07             process.waitFor(); 

08         } catch (Exception e) { 

09             System.out.println("Error executing notepad."); 

10         } 

11         System.out.println("Notepad returned " + process.exitValue()); 

12     } 

13 }