Advertisement
Guest User

Untitled

a guest
Nov 16th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /**
  2. * this method run any terminal command
  3. * @param command
  4. * @return
  5. */
  6. public static String runProcessCommand(String command) {
  7. try {
  8. Timber.tag(TAG_APK_UTILS).i("runProcessCommand [command: %s]", "su -c " + command);
  9. String commands[] = { "su", "-c", command};
  10. // Process process1 = Runtime.getRuntime().exec(commands);
  11.  
  12. Process process = Runtime.getRuntime().exec("su");
  13. DataOutputStream os = new DataOutputStream(process.getOutputStream());
  14. os.writeBytes(command);
  15. os.flush();
  16. os.writeBytes("exit\n");
  17. os.flush();
  18. process.waitFor();
  19. return getResultFromProcess(process);
  20. } catch (IOException e) {
  21. Timber.tag(TAG_APK_UTILS).e(e,"runProcessCommand >> IOException");
  22. e.printStackTrace();
  23. } catch (InterruptedException e) {
  24. Timber.tag(TAG_APK_UTILS).e(e,"runProcessCommand >> InterruptedException");
  25. e.printStackTrace();
  26. }
  27. //Some problem happened to execute update apk
  28. return null;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement