Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Runtime.getRuntime().exec("su") java.io.IOException: Permission denied

When I use this code:

process = Runtime.getRuntime().exec("su");
os = new DataOutputStream(process.getOutputStream());

there is always an error, any ideas? Running on an android virtual device

W/System.err(3211): java.io.IOException: Error running exec(). Command: [su] Working Directory: null Environment: null
W/System.err(3211):     at java.lang.ProcessManager.exec(ProcessManager.java:211)
W/System.err(3211):     at java.lang.Runtime.exec(Runtime.java:174)
W/System.err(3211):     at java.lang.Runtime.exec(Runtime.java:247)
W/System.err(3211):     at java.lang.Runtime.exec(Runtime.java:190)
W/System.err(3211):     at com.example.executeandroidtest.ShellUtils.execCommand(MainActivity.java:661)
W/System.err(3211):     at com.example.executeandroidtest.MainActivity$3.run(MainActivity.java:410)
W/System.err(3211):     at java.lang.Thread.run(Thread.java:818)
W/System.err(3211): Caused by: java.io.IOException: Permission denied
W/System.err(3211):     at java.lang.ProcessManager.exec(Native Method)
W/System.err(3211):     at java.lang.ProcessManager.exec(ProcessManager.java:209)
W/System.err(3211):     ... 6 more
like image 989
GuiYQ Avatar asked Nov 20 '22 22:11

GuiYQ


1 Answers

Caused by: java.io.IOException: Permission denied

  1. find where su is, for instance: /system/xbin/su
  2. check su's file permission: ls -al /system/xbin/su
  3. change mod if necessary: chmod 4755 su
  4. try again.
like image 179
meng yang Avatar answered Jun 29 '23 05:06

meng yang