更新时间:2023-12-03 23:32:46
你的方式与我可能会做的差不多:
Your way isn't far off from what I'd probably do:
Runtime r = Runtime.getRuntime();
Process p = r.exec("uname -a");
p.waitFor();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
while ((line = b.readLine()) != null) {
System.out.println(line);
}
b.close();
当然可以处理您关心的任何异常.
Handle whichever exceptions you care to, of course.