@Test public void linuxCommand() throws Exception { try { //执行的linux指令 String cmd = "uname -m"; String[] cmdA = {"/bin/sh", "-c", cmd}; Process process = Runtime.getRuntime().exec(cmdA); process.waitFor(); LineNumberReader br = new LineNumberReader(new InputStreamReader( process.getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } //获取结果 System.out.println(sb.toString().trim()); } catch (Exception e) { e.printStackTrace(); } }