我试图廉价并uname -a在Java中执行本地系统命令().我希望从中获取输出uname并将其存储在String中.这样做的最佳方式是什么?当前代码:
public class lame {
public static void main(String args[]) {
try {
Process p = Runtime.getRuntime().exec("uname -a");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
}
catch(IOException e1) {}
catch(InterruptedException e2) {}
System.out.println("finished.");
}
}
Run Code Online (Sandbox Code Playgroud)