Skip to content

Instantly share code, notes, and snippets.

@bodiam
Created September 9, 2013 23:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bodiam/6502781 to your computer and use it in GitHub Desktop.
Save bodiam/6502781 to your computer and use it in GitHub Desktop.
A sudo example for stackoverflow. Note that this on is NOT working.
public static void main(String[] args) throws IOException {
Process pb = new ProcessBuilder("sudo", "ls").start();
OutputStream out = pb.getOutputStream();
out.write(password.getBytes());
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(pb.getInputStream()));
while ((line = input.readLine()) != null) {
System.out.println(line);
}
input.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment