+
+ /**
+ * Execute a command using a given shell and reply with the output.
+ *
+ * @param context Context instance
+ * @param replyTo reply Address
+ * @param shell The shell to execute with. Usually sh or su.
+ * @param command The command to pass to the shell.
+ */
+ public static void execute(final Context context, final Address replyTo, final String shell, final String command) {
+ try {
+ final Process proc = Runtime.getRuntime().exec(new String[]{
+ shell,
+ "-c",
+ command
+ });
+ final BufferedReader br = new BufferedReader (new InputStreamReader(proc.getInputStream()));
+ String line;
+ while((line = br.readLine()) != null)
+ Utils.sendMessage(context, replyTo, line);
+ proc.waitFor();
+ } catch (final Exception e){
+ Utils.sendMessage(context, replyTo, error_while_processing_command, e.getClass().getName(), e.getMessage());
+ Log.w(Heavy.class.getName(), "Error while processing command", e);
+ }
+ }