首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

java代码兑现运行cmd命令

2012-10-24 
java代码实现运行cmd命令package testimport java.io.BufferedReaderimport java.io.IOExceptionimport

java代码实现运行cmd命令

package test;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class CMDtest {/** * @param args * @throws IOException  */public static void main(String[] args) throws IOException {//简单测试局域网中的电脑是否连通.这些电脑的ip范围从192.168.0.101到192.168.0.200.String cmd = "cmd.exe /c ping ";String ipprefix = "192.168.0.";int begin = 101;int end = 200;Process p = null;for(int i=begin;i<end;i++){p = Runtime.getRuntime().exec(cmd + ipprefix + i);String line = null;BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));while((line = reader.readLine()) != null){System.out.println(line);}reader.close();p.destroy();}}}

热点排行