use of com.ms.silverking.process.ProcessExecutor in project SilverKing by Morgan-Stanley.
the class DF method df.
public static Triple<Long, Long, Integer> df(String path, int timeoutInSeconds) throws IOException, RuntimeException {
ProcessExecutor pe;
String[] commands;
String rawOutput;
commands = new String[3];
commands[0] = dfCommand;
commands[1] = "-k";
commands[2] = path;
pe = new ProcessExecutor(commands, timeoutInSeconds);
pe.execute();
if (pe.getExitCode() != 0) {
throw new RuntimeException("non-zero df exit code: " + pe.getExitCode());
}
rawOutput = pe.getOutput();
if (rawOutput == null) {
throw new RuntimeException("null df output: ");
} else {
String[] output;
int line2Index;
line2Index = rawOutput.indexOf('/');
if (line2Index < 0) {
throw new RuntimeException("Unexpected df output: " + rawOutput);
} else {
String line2;
line2 = rawOutput.substring(line2Index);
output = line2.split("\\s+");
try {
long totalBlocks;
long usedBlocks;
totalBlocks = Long.parseLong(output[1]);
usedBlocks = Long.parseLong(output[2]);
return new Triple<>(totalBlocks, usedBlocks, blockSize);
} catch (RuntimeException re) {
Log.logErrorWarning(re);
throw new RuntimeException("Exception parsing output: " + rawOutput, re);
}
}
}
}
use of com.ms.silverking.process.ProcessExecutor 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);
}
Aggregations