Android Question Put a command on shell

klingon467

Member
Licensed User
Longtime User
Hi,
i want to send a command into shell on my device i use this:

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

i can send a command into "Command" variable?
for example, to see a list of the root file and folder?

cd /
ls -lrt

thanks
 

DonManfred

Expert
Licensed User
Longtime User
If your device is rooted (must be to access this folder) you can try RootCMD library
 
Upvote 0

klingon467

Member
Licensed User
Longtime User
I dont know whether this lib captures the output or not.
I would try to call a command which prints the ls output to a file and after that i would try to read that file.
i use your lib but i have this error:

B4X:
mHaveRoot = true, have root!
mHaveRoot = true, have root!
pm install -r /mnt/sdcard/catturascreen.apk
java.lang.RuntimeException: Object should first be initialized (Exception).

for install apk i use this:
B4X:
Sub InstAPK(apkfile As String)
If rc.haveRoot Then
If rc.InstallApk(File.DirRootExternal & "/" & apkfile) Then
        manna("APKINSTlog" & "SPLT" & "Install success")
    Else
        manna("APKINSTlog" & "SPLT" & LastException.Message)
End If
    Else
        manna("APKINSTlog" & "SPLT" & "There is no root!")
End If
End Sub

usage: InstAPK("catturascreen.apk")

What needs to be initialized??
 
Upvote 0

klingon467

Member
Licensed User
Longtime User
i use your lib but i have this error:

B4X:
mHaveRoot = true, have root!
mHaveRoot = true, have root!
pm install -r /mnt/sdcard/catturascreen.apk
java.lang.RuntimeException: Object should first be initialized (Exception).

for install apk i use this:
B4X:
Sub InstAPK(apkfile As String)
If rc.haveRoot Then
If rc.InstallApk(File.DirRootExternal & "/" & apkfile) Then
        manna("APKINSTlog" & "SPLT" & "Install success")
    Else
        manna("APKINSTlog" & "SPLT" & LastException.Message)
End If
    Else
        manna("APKINSTlog" & "SPLT" & "There is no root!")
End If
End Sub

usage: InstAPK("catturascreen.apk")

What needs to be initialized??
@icefairy333
 
Upvote 0
Top