Stericson / RootTools

RootTools Library
1.6k stars 484 forks source link

How to finish a command #41

Closed MFlisar closed 6 years ago

MFlisar commented 9 years ago

If I execute a set of commands, commandCompleted is never called. Do I have to call it manually? I tried adding a exit\n command, but that does not solve the problem either. Following works, but it's just a workaround. How is meant to be used correctly?

Command command = new Command(0, true, getCommandSu(), "ps\n", "echo EXIT") {
        @Override
        public void commandOutput(int id, String line) {
            // use cmd output...

            // finish command
            if (line.equals("EXIT"))
                commandFinished();
        }

        @Override
        public void commandCompleted(int id, int exitCode) {
            L.d("COMPLETED (" + exitCode + ")");
        }
    };
    shell.runCommand(command);
    while (!command.isFinished()) {
        Thread.sleep(50);
    }
Stericson commented 9 years ago

Normally you wouldn't call this method directly. However, the logic you have implemented should work.

2 things here:

  1. You should be calling the super method for commandOuput
  2. Can you debug your if condition and ensure commandFinished is being called?
MFlisar commented 9 years ago

I will try 1 - makes sense anywayd... And to 2, yes, this works perfectly fine, my commandFinished is called if I do it this way...