Search in sources :

Example 1 with ExitCodeException

use of org.apache.zookeeper.Shell.ExitCodeException in project SilverKing by Morgan-Stanley.

the class Ping method ping.

public Pair<Boolean, String> ping(String dest, int count) throws IOException {
    ProcessExecutor pe;
    String[] cmd;
    boolean ok;
    String output;
    cmd = new String[4];
    cmd[0] = ping;
    cmd[1] = "-c";
    cmd[2] = Integer.toString(count);
    cmd[3] = dest;
    pe = new ProcessExecutor(cmd);
    try {
        pe.execute();
        ok = pe.getExitCode() == 0;
        output = pe.getOutput();
    } catch (ExitCodeException ece) {
        ok = false;
        output = null;
    }
    return new Pair<>(ok, output);
}
Also used : ProcessExecutor(com.ms.silverking.process.ProcessExecutor) ExitCodeException(org.apache.zookeeper.Shell.ExitCodeException) Pair(com.ms.silverking.collection.Pair)

Aggregations

Pair (com.ms.silverking.collection.Pair)1 ProcessExecutor (com.ms.silverking.process.ProcessExecutor)1 ExitCodeException (org.apache.zookeeper.Shell.ExitCodeException)1