Guest User

Untitled

a guest
Sep 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. Execute linux command as superuser by default [closed]
  2. Runtime.getRuntime().exec("su")
  3.  
  4. public void runCommandsAsRoot(String[] cmds) throws IOException {
  5. Process proc = Runtime.getRuntime().exec("su");
  6.  
  7. DataOutputStream oStream = new DataOutputStream(proc.getOutputStream());
  8.  
  9. for (String cmd : cmds) {
  10. oStream.writeBytes(cmd + "n");
  11. }
  12.  
  13. oStream.writeBytes("exitn");
  14. oStream.flush();
  15. }
  16.  
  17. String[] commands = { "fistCommand", "secondCommand" };
  18. runCommandsAsRoot(commands);
Add Comment
Please, Sign In to add comment