Android Question run error when use SHELL

carycai

Member
Licensed User
Longtime User
when i try to run some commands in my android device(with root),i get the stderr as below:

StdErr:/data/data/com.scanner.cary/cache/runner[2]: su: not found

but in ADB SHELL,i input "su",there is. (222.png)
when i key down the command in ADB SHELL: "sh /data/data/com.scanner.cary/cache/runner",everything is OK.
I confused.
please help me,thks.


the sub RunCMD as below:

B4X:
Sub RunCMD(str As String) As Int
    Dim Command, Runner As String
    Dim StdOut, StdErr As StringBuilder
    Dim Result As Int
    Dim Ph As Phone
    StdOut.Initialize
    StdErr.Initialize
    File.Delete(File.DirInternalCache, "runner")
    File.Delete(File.DirInternalCache, "command")
    Runner = File.Combine(File.DirInternalCache, "runner")
    Command = File.Combine(File.DirInternalCache, "command")
    File.WriteString(File.DirInternalCache, "runner", "su < " & Command)
    File.WriteString(File.DirInternalCache, "command", str & CRLF & "exit") 'Any commands via crlf, and exit at end
    Log("runner:" & Runner)
    Result = Ph.Shell("sh",Array As String(Runner), StdOut, StdErr)
    Log("stdout:" & StdOut.tostring)
    Log("StdErr:" & StdErr.tostring)
    Return Result

End Sub

https://www.b4x.com/android/forum/threads/running-shell-commands-as-superuser.6886/
 

Attachments

  • 222.png
    222.png
    44.7 KB · Views: 344

carycai

Member
Licensed User
Longtime User
Hi Erel
thks for your reply.

I try to set the command as below:
B4X:
Sub RunCMD(str As String) As Int
    Dim Command, Runner As String
    Dim StdOut, StdErr As StringBuilder
    Dim Result As Int
    Dim Ph As Phone
    StdOut.Initialize
    StdErr.Initialize
    File.Delete(File.DirInternalCache, "runner")
    File.Delete(File.DirInternalCache, "command")
    Runner = File.Combine(File.DirInternalCache, "runner")
    Command = File.Combine(File.DirInternalCache, "command")
    File.WriteString(File.DirInternalCache, "runner", "/system/xbin/su < " & Command)
    File.WriteString(File.DirInternalCache, "command", str & CRLF & "exit") 'Any commands via crlf, and exit at end
    Log("runner:" & Runner)
    Result = Ph.Shell("sh",Array As String(Runner), StdOut, StdErr)
    Log("stdout:" & StdOut.tostring)
    Log("StdErr:" & StdErr.tostring)
    Return Result

End Sub

and i get the the same not found error: StdErr:/data/data/com.scanner.cary/cache/runner[2]: /system/xbin/su: not found

then, i try to excute the command:
adb root
adb shell setenfoerce 0 ==> by the way, setenfoerce should correct as “setenforce”

and get the error: StdErr:/data/data/com.scanner.cary/cache/runner[2]: /system/xbin/su: can't execute: Permission denied

Is there anything else i can do? I focus in this error for a day !!
 
Upvote 0
Top