Stericson / RootTools

RootTools Library
1.6k stars 484 forks source link

access to Process for manual pipe handling #35

Closed M1cha closed 9 years ago

M1cha commented 9 years ago

I'd like to manually handle stdin/stdout/sterr and just want to start a process as root. It would be great if you could add a method to start start a Process as root and return the resulting "Process" Object.

M1cha commented 9 years ago

I just saw that I can use:

Runtime.getRuntime().exec("su -c \"/path/to/binary\"");

I thought it would be more complicated since RootShell has a lot code to do this.

Stericson commented 9 years ago

Hey,

Yep, it's that simple.

RootShell has a lot more code in it because it handles everything. It keeps the shell open, handles processing input and output, as well as making sure commands don't stay running too long and cause a ANR and it also handles keeping a long running process open by setting the command timeout to 0.

Rootshell technically also has support for multiple shells at one time (one root Shell, one normal shell, and one custom shell)

M1cha commented 9 years ago

what I did might be interesting for RootTools, too. I wrote a small binary called syscall_server which runs in the background all time and - as the name might suggest - allows you to execute syscall commands from stdin.

This way I can simply read/write files with custom input and output streams and I don't need to copy files to the app cache anymore.

Here's the C++ part: https://github.com/grub4android/external_syscallserver/blob/master/syscall_server.c I didn't upload the java part yet, but the usage is as easy as: "new RootOutputStream(file);"