Search in sources :

Example 1 with CommandFailedException

use of com.wuntee.oter.exception.CommandFailedException in project otertool by wuntee.

the class AdbWorkshop method installApk.

public static void installApk(String apk) throws IOException, InterruptedException, CommandFailedException {
    TerminatingCommand c = AdbWorkshop.getTerminatingAdbCommand(new String[] { "install", apk });
    c.execute();
    for (String l : c.getOutput()) {
        // Failure [INSTALL_FAILED_ALREADY_EXISTS]
        if (l.matches(".*Failure.*")) {
            throw new CommandFailedException(c.getCommand(), c.getOutput(), l);
        }
    }
}
Also used : TerminatingCommand(com.wuntee.oter.command.TerminatingCommand) CommandFailedException(com.wuntee.oter.exception.CommandFailedException)

Example 2 with CommandFailedException

use of com.wuntee.oter.exception.CommandFailedException in project otertool by wuntee.

the class TerminatingCommand method executeNoErrorMonitor.

public int executeNoErrorMonitor() throws CommandFailedException, InterruptedException, IOException {
    this.child = Runtime.getRuntime().exec(this.command);
    BufferedReader b = new BufferedReader(new InputStreamReader(this.child.getInputStream()));
    String l;
    while ((l = b.readLine()) != null) {
        logger.debug("STDOUT: " + l);
        ;
        output.add(l);
    }
    this.returnCode = this.child.waitFor();
    logger.debug("Return code: " + this.returnCode);
    if (this.returnCode != 0) {
        List<String> ex = new LinkedList<String>();
        ex.addAll(output);
        ex.addAll(error);
        throw new CommandFailedException(this.command, ex, this.returnCode);
    }
    return (this.returnCode);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList) CommandFailedException(com.wuntee.oter.exception.CommandFailedException)

Example 3 with CommandFailedException

use of com.wuntee.oter.exception.CommandFailedException in project otertool by wuntee.

the class TerminatingCommand method execute.

public int execute() throws IOException, InterruptedException, CommandFailedException {
    if (workingDirectory != null) {
        String cmd = "";
        for (String c : this.command) {
            cmd = cmd + c + " ";
        }
        logger.debug("Executing command: " + cmd + " in working directory:" + workingDirectory);
        this.child = Runtime.getRuntime().exec(this.command, new String[] {}, workingDirectory);
    } else {
        this.child = Runtime.getRuntime().exec(this.command);
    }
    BufferedReader b = new BufferedReader(new InputStreamReader(this.child.getErrorStream()));
    String l;
    while ((l = b.readLine()) != null) {
        logger.debug("STDERR: " + l);
        error.add(l);
    }
    b = new BufferedReader(new InputStreamReader(this.child.getInputStream()));
    while ((l = b.readLine()) != null) {
        logger.debug("STDOUT: " + l);
        ;
        output.add(l);
    }
    this.returnCode = this.child.waitFor();
    logger.debug("Return code: " + this.returnCode);
    if (this.returnCode != 0) {
        List<String> ex = new LinkedList<String>();
        ex.addAll(output);
        ex.addAll(error);
        throw new CommandFailedException(this.command, ex, this.returnCode);
    }
    return (this.returnCode);
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList) CommandFailedException(com.wuntee.oter.exception.CommandFailedException)

Aggregations

CommandFailedException (com.wuntee.oter.exception.CommandFailedException)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2 LinkedList (java.util.LinkedList)2 TerminatingCommand (com.wuntee.oter.command.TerminatingCommand)1