Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,21 @@ public static CommandResult execCmd(final String command, final boolean isRooted
return execCmd(new String[]{command}, isRooted, true);
}

/**
* Execute the command.
*
* @param command The command.
* @param envp The environment variable settings.
* @param isRooted True to use root, false otherwise.
* @return the single {@link CommandResult} instance
*/
public static CommandResult execCmd(final String command, final List<String> envp, final boolean isRooted) {
return execCmd(new String[]{command},
envp == null ? null : envp.toArray(new String[]{}),
isRooted,
true);
}

/**
* Execute the command.
*
Expand All @@ -144,6 +159,23 @@ public static CommandResult execCmd(final List<String> commands, final boolean i
return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRooted, true);
}

/**
* Execute the command.
*
* @param commands The commands.
* @param envp The environment variable settings.
* @param isRooted True to use root, false otherwise.
* @return the single {@link CommandResult} instance
*/
public static CommandResult execCmd(final List<String> commands,
final List<String> envp,
final boolean isRooted) {
return execCmd(commands == null ? null : commands.toArray(new String[]{}),
envp == null ? null : envp.toArray(new String[]{}),
isRooted,
true);
}

/**
* Execute the command.
*
Expand All @@ -169,6 +201,40 @@ public static CommandResult execCmd(final String command,
return execCmd(new String[]{command}, isRooted, isNeedResultMsg);
}

/**
* Execute the command.
*
* @param command The command.
* @param envp The environment variable settings.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public static CommandResult execCmd(final String command,
final List<String> envp,
final boolean isRooted,
final boolean isNeedResultMsg) {
return execCmd(new String[]{command}, envp == null ? null : envp.toArray(new String[]{}),
isRooted,
isNeedResultMsg);
}

/**
* Execute the command.
*
* @param command The command.
* @param envp The environment variable settings array.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public static CommandResult execCmd(final String command,
final String[] envp,
final boolean isRooted,
final boolean isNeedResultMsg) {
return execCmd(new String[]{command}, envp, isRooted, isNeedResultMsg);
}

/**
* Execute the command.
*
Expand Down Expand Up @@ -196,6 +262,26 @@ public static CommandResult execCmd(final List<String> commands,
public static CommandResult execCmd(final String[] commands,
final boolean isRooted,
final boolean isNeedResultMsg) {
return execCmd(commands, null, isRooted, isNeedResultMsg);
}

/**
* Execute the command.
*
* @param commands The commands.
* @param envp Array of strings, each element of which
* has environment variable settings in the format
* <i>name</i>=<i>value</i>, or
* <tt>null</tt> if the subprocess should inherit
* the environment of the current process.
* @param isRooted True to use root, false otherwise.
* @param isNeedResultMsg True to return the message of result, false otherwise.
* @return the single {@link CommandResult} instance
*/
public static CommandResult execCmd(final String[] commands,
final String[] envp,
final boolean isRooted,
final boolean isNeedResultMsg) {
int result = -1;
if (commands == null || commands.length == 0) {
return new CommandResult(result, "", "");
Expand All @@ -207,7 +293,7 @@ public static CommandResult execCmd(final String[] commands,
StringBuilder errorMsg = null;
DataOutputStream os = null;
try {
process = Runtime.getRuntime().exec(isRooted ? "su" : "sh");
process = Runtime.getRuntime().exec(isRooted ? "su" : "sh", envp, null);
os = new DataOutputStream(process.getOutputStream());
for (String command : commands) {
if (command == null) continue;
Expand Down