notNull(command, "command");
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
DefaultExecutor executor = prepareDefaultExecutor(command);
// handle error and output of the process and write them to the given
// out stream
PumpStreamHandler handler = new PumpStreamHandler(out, err, command.getInput());
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);