in src/main/java/com/epam/grid/engine/cmd/SimpleCmdExecutor.java [45:72]
public CommandResult execute(final String... arguments) {
final ProcessBuilder processBuilder = new ProcessBuilder();
processBuilder.command(arguments);
Process process = null;
try {
process = processBuilder.start();
final AsyncOutputReader asyncOutputReader = new AsyncOutputReader(process);
final List<String> stdOut = new ArrayList<>();
final List<String> stdErr = new ArrayList<>();
asyncOutputReader.readLinesToLists(stdOut, stdErr);
final int exitCode = process.waitFor();
asyncOutputReader.shutdown();
return new CommandResult(stdOut, exitCode, stdErr);
} catch (final InterruptedException | ExecutionException e) {
Thread.currentThread().interrupt();
throw new GridEngineException(HttpStatus.NOT_FOUND,
"Something went wrong while executing the command: " + String.join(SPACE, arguments), e);
} catch (final RuntimeException | IOException e) {
throw new GridEngineException(HttpStatus.NOT_FOUND,
"Something went wrong while reading output of the command: " + String.join(SPACE, arguments), e);
} finally {
if (process != null && process.isAlive()) {
process.destroy();
}
}
}