public class Shell
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Shell.Builder
Builder class for
Shell.Interactive |
static class |
Shell.Interactive
An interactive shell - initially created with
Shell.Builder -
that executes blocks of commands you supply in the background, optionally
calling callbacks as each block completes. |
static interface |
Shell.OnCommandLineListener
Command per line callback for parsing the output line by line without
buffering It also notifies the recipient of the completion of a command
block, including the (last) exit code.
|
static interface |
Shell.OnCommandResultListener
Command result callback, notifies the recipient of the completion of a
command block, including the (last) exit code, and the full output
|
static class |
Shell.SH
This class provides utility functions to easily execute commands using SH
|
static class |
Shell.SU
This class provides utility functions to easily execute commands using SU
(root shell), as well as detecting whether or not root is available, and
if so which version.
|
| Modifier and Type | Field and Description |
|---|---|
protected static java.lang.String[] |
availableTestCommands |
| Constructor and Description |
|---|
Shell() |
| Modifier and Type | Method and Description |
|---|---|
protected static boolean |
parseAvailableResult(java.util.List<java.lang.String> ret,
boolean checkForRoot)
See if the shell is alive, and if so, check the UID
|
static java.util.List<java.lang.String> |
run(java.lang.String shell,
java.lang.String[] commands,
boolean wantSTDERR)
Deprecated.
|
static java.util.List<java.lang.String> |
run(java.lang.String shell,
java.lang.String[] commands,
java.lang.String[] environment,
boolean wantSTDERR)
Runs commands using the supplied shell, and returns the output, or null
in case of errors.
|
@Deprecated
public static java.util.List<java.lang.String> run(java.lang.String shell,
java.lang.String[] commands,
boolean wantSTDERR)
Runs commands using the supplied shell, and returns the output, or null in case of errors.
This method is deprecated and only provided for backwards compatibility.
Use run(String, String[], String[], boolean) instead, and see
that same method for usage notes.
shell - The shell to use for executing the commandscommands - The commands to executewantSTDERR - Return STDERR in the output ?public static java.util.List<java.lang.String> run(java.lang.String shell,
java.lang.String[] commands,
java.lang.String[] environment,
boolean wantSTDERR)
Runs commands using the supplied shell, and returns the output, or null in case of errors.
Note that due to compatibility with older Android versions, wantSTDERR is not implemented using redirectErrorStream, but rather appended to the output. STDOUT and STDERR are thus not guaranteed to be in the correct order in the output.
Note as well that this code will intentionally crash when run in debug mode from the main thread of the application. You should always execute shell commands from a background thread.
When in debug mode, the code will also excessively log the commands passed to and the output returned from the shell.
Though this function uses background threads to gobble STDOUT and STDERR so a deadlock does not occur if the shell produces massive output, the output is still stored in a List<String>, and as such doing something like 'ls -lR /' will probably have you run out of memory.
shell - The shell to use for executing the commandscommands - The commands to executeenvironment - List of all environment variables (in 'key=value'
format) or null for defaultswantSTDERR - Return STDERR in the output ?protected static boolean parseAvailableResult(java.util.List<java.lang.String> ret,
boolean checkForRoot)
ret - Standard output from running availableTestCommandscheckForRoot - true if we are expecting this shell to be running as
root