String command1 = "hadoop fs -du "+str +" |awk ' { SUM += $1 } END { print SUM/(1024*1024) }'" ;
String[] command = { "/bin/sh", "-c", command1 };
try {
Process exec = Runtime.getRuntime().exec(command);
BufferedReader br = new BufferedReader(new InputStreamReader(exec.getInputStream()));
StringBuffer sb = new StringBuffer();
String line;
while ((line = br.readLine()) != null) {
//执行结果加上回车
sb.append(line);
}
String result1 = sb.toString();
node.put("storageSpace",result1+"MB");
System.out.println(result);
} catch (IOException e) {
e.printStackTrace();
}
}
以上述方式执行即可