public void useLinuxCommond(){ try { Process p = Runtime.getRuntime().exec("sudo ovs-vsctl show"); //调用Linux的相关命令 InputStreamReader ir = new InputStreamReader(p.getInputStream()); LineNumberReader input = new LineNumberReader (ir); //创建IO管道,准备输出命令执行后的显示内容 String line; while ((line = input.readLine ()) != null){ //按行打印输出内容 System.out.println(line); } } catch (IOException e) { e.printStackTrace(); } }
?