dumpe2fs /dev/sda3这个命令在linux终端里可以获取到数据,java中获取不到
代码:
String cmd = "dumpe2fs /dev/sda3";
public List<String> Cmd(String cmd) {
List<String> cmdList = new ArrayList<>();
try {
Process process = Runtime.getRuntime().exec(new String[] { "/bin/sh", "-c", cmd });
InputStreamReader ir = new InputStreamReader(process.getInputStream());
LineNumberReader input = new LineNumberReader(ir);
String line = null;
while ((line = input.readLine()) != null) {// 输出结果
cmdList.add(line);
}
} catch (java.io.IOException e) {
System.err.println("IOException " + e.getMessage());// 捕捉异常
}
return cmdList;
}
出现这种情况是因为dumpe2fs 需要root权限 打成jar然后root运行 数据是存在的
https://blog.csdn.net/dn98201/article/details/78670278
我root用户登录了,centos6.8的版本,还是会报错