我想你可以使用它,但是我有点犹豫要发布它。所以我只想说:
使用此方法后果自负,不建议你使用,请勿起诉我,等等。
public static void main(String[] args) throws IOException { String[] cmd = {"/bin/bash","-c","echo password| sudo -S ls"}; Process pb = Runtime.getRuntime().exec(cmd); String line; BufferedReader input = new BufferedReader(new InputStreamReader(pb.getInputStream())); while ((line = input.readLine()) != null) { System.out.println(line); } input.close();}


