str为命令,此处为主要方法
public static String call(String str) throws IOException {
if (str == null || str.length() == 0) {
return null;
}
Process process = Runtime.getRuntime().exec(str);
BufferedReader strCon = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String line;
StringBuffer sb = new StringBuffer();
while ((line = strCon.readLine()) != null) {
sb.append("***line****"+line);
sb.append("\n");
}
strCon.close();
process.destroy();
return sb.toString();
}
可以参考https://blog.csdn.net/whj826069748/article/details/82252487