1.java打开cmd
public static void open() {
try {
Runtime run = Runtime.getRuntime();
System.out.println("准备打开cmd");
//启动cmd窗口
run.exec("cmd /k start cmd.exe");
} catch (IOException e) {
System.out.println("ERROR!");
e.printStackTrace();
}
}
2.java在cmd中运行ping功能,不需要返回值.
public static void open() {
try {
Runtime run = Runtime.getRuntime();
run.exec("cmd /k start ping -t 192.168.1.34");
} catch (IOException e) {
System.out.println("ERROR!");
e.printStackTrace();
}
}
效果图
3.java实现ping功能,并将返回结果在控制台打印出来