标签:buffere NPU class version param nbsp com cat proc
package com.cmd; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class Test { /** * 调用方法 * @param cmd cmd命令 * @return */ public static String exec(String cmd) { try { Runtime rt = Runtime.getRuntime(); Process proc = rt.exec(cmd); InputStream es = proc.getErrorStream(); String line; BufferedReader br; br = new BufferedReader(new InputStreamReader(es, "GBK")); StringBuffer buffer=new StringBuffer(); while ((line = br.readLine()) != null) { buffer.append(line+"\n"); } return buffer.toString(); } catch (Exception e) { e.printStackTrace(); } return null; } public static void main(String[] args) { System.out.println(exec("java -version")); } }
标签:buffere NPU class version param nbsp com cat proc
原文地址:https://www.cnblogs.com/pxblog/p/13111273.html