@Override
protected ProcessResult process(Object input) throws Exception {
Validate.executionNotNull(commandBuilder, "Command must not be null");
Command command = commandBuilder.build();
Process process = null;
Execution<Process> spawnedProcess = Tasks.prepare(SpawnProcessTask.class)
.redirectErrorStream(true)
.shouldExitWith(allowedExitCodes)
.command(command)
.workingDir(workingDirectory)
.addEnvironment(environment)
.runAsDaemon(isDaemon)
.execute();
// wait for process to finish
process = spawnedProcess.await();
// set processReference
processRef.setProcess(process);
// handle IO of spawned process
Execution<ProcessResult> processConsumer = Tasks.chain(spawnedProcess, ConsumeProcessOutputTask.class)
.programName(command.getProgramName()).interaction(interaction).execute();
// wait for process to finish IO
ProcessResult result = processConsumer.await();
if (spawnedProcess.hasFailed()) {