Return output from completed command using RootTools

246 Views Asked by At

I'm trying to retrieve the output of commandOutput in order to pass it to another function, but commandCompleted is never ran. Any help?

Command command = new Command(0, "cat " + file){
    private String output;
    @Override
    public void commandCompleted(int id, int exitCode) {
        Log.d("Commands.Completed", output);
        Log.d("Commands.Completed", "ID: " + id + " & exitCode: " + exitCode);
        saveData(output);
    }

    @Override
    public void commandOutput(int id, String line) {
        output += line + "\n";
    }

    @Override
    public void commandTerminated(int id, String reason) {
    }
};

try {
    RootTools.getShell(true).add(command);
} catch (IOException | RootDeniedException | TimeoutException e) {
    e.printStackTrace();
}
1

There are 1 best solutions below

0
MaxChinni On

Your commandCompleted(int id, int exitCode) implementation is missing

super.commandCompleted(id, exitCode);

could it be the problem?

If you imported RootTools as

import com.stericson.RootTools.*;

you could also be using RootTools.Log which is muted by default. Maybe try to use

android.util.Log.d("Commands.Completed", output);

just to exclude the case.