executor.setStreamHandler(handler);
CommandLine cl = toCommandLine(command);
try {
int exitValue = executor.execute(cl);
// if the size is zero, we have no output, so construct the result
// with null (required by ExecResult)
InputStream stdout = out.size() == 0 ? null : new ByteArrayInputStream(out.toByteArray());
InputStream stderr = err.size() == 0 ? null : new ByteArrayInputStream(err.toByteArray());
ExecResult result = new ExecResult(command, stdout, stderr, exitValue);