Java执行windows的cmd命令
Runtime runtime=Runtime.getRuntime(); String command="cmd.exe /c ipconfig /all"; Process process=null; try { System.out.println("start"); process=null; process=runtime.exec(command); System.out.println("finish"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(process==null){ return; } BufferedReader reader=null; try { reader = new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK")); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if(reader==null){ return; } try { String s=reader.readLine(); while(s!=null){ System.out.println(s); s=reader.readLine(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); }
本文出自 “Focus_000” 博客,请务必保留此出处http://120806872.blog.51cto.com/8289253/1547936
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。