我有使用问题Runtime.getRuntime().exec
String line = "";
String output = "";
Process p = Runtime.getRuntime().exec(new String[]{"dmidecode | grep UUID:"});
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output += (line + '\n').trim();
}
input.close();
我对此进行了测试并且无法正常工作
String line = "";
String output = "";
Process p = Runtime.getRuntime().exec("dmidecode | grep UUID");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
while ((line = input.readLine()) != null) {
output += (line + '\n').trim();
}
input.close();
我在 linux 机器上得到下一个错误:
java.io.IOException: Cannot run program "dmidecode | grep UUID:": error no such file or directory
但是我在控制台中测试了命令,我得到了结果!
dmidecode | grep UUID:=> UUID: 564DAF5F-FBF7-5FEE-6BA4-67F0B12D8E0E
如何使用基于 Java 的方法获得相同的结果Process
?