package com.yanek.util; import java.io.IOException; import java.io.InputStreamReader; import java.io.LineNumberReader; public class Tool { /** * @param args */ public static void main(String[] args) { System.out.println(executeCommond("ipconfig")); } /** * java方法执行控制台命令,返回执行的输入结果 * @param cmd * @return */ public static String executeCommond(String cmd) { String ret = ""; try { Process p = Runtime.getRuntime().exec(cmd); InputStreamReader ins = new InputStreamReader(p.getInputStream()); LineNumberReader input = new LineNumberReader(ins); String line; while ((line = input.readLine()) != null) { System.out.println(line); ret += line + "<br>"; } } catch (IOException e) { e.printStackTrace(); } return ret; } }
时间: 2024-11-03 23:39:13