ByteArrayOutputStream errStream = new ByteArrayOutputStream();
ProcessExecutor executor = new ProcessExecutor().command(command)
.readOutput(true)
.redirectOutput(outStream)
.redirectError(errStream);
ProcessResult result = executor.execute();
if (result.getExitValue() != 0) {
LOG.error(result.getOutput().getString());
throw new RuntimeException(String.format("mongoimport failed with exit code %d: %s", result.getExitValue(),
result.getOutput().getString()));
}