errorGobbler.start();
final Process finalProcess = process;
- Callable<Integer> call = new Callable<Integer>() {
+ executorService = Executors.newSingleThreadExecutor();
+ Future<Integer> ft = executorService.submit(new Callable<Integer>() {
public Integer call() throws Exception {
return finalProcess.waitFor();
}
- };
-
- executorService = Executors.newSingleThreadExecutor();
- Future<Integer> ft = executorService.submit(call);
+ });
int exitCode = ft.get(timeoutMilliseconds, TimeUnit.MILLISECONDS);
waitUntilFinish(outputGobbler);
waitUntilFinish(errorGobbler);
- if (outputGobbler.getException() != null) {
- throw new CommandException(command, "Error inside stdOut parser", outputGobbler.getException());
- }
- if (errorGobbler.getException() != null) {
- throw new CommandException(command, "Error inside stdErr parser", errorGobbler.getException());
- }
+ verifyGobbler(command, outputGobbler, "stdOut");
+ verifyGobbler(command, errorGobbler, "stdErr");
return exitCode;
} catch (TimeoutException te) {
}
}
+ private void verifyGobbler(Command command, StreamGobbler gobbler, String type) {
+ if (gobbler.getException() != null) {
+ throw new CommandException(command, "Error inside " + type + " stream", gobbler.getException());
+ }
+ }
+
/**
* Execute command and display error and output streams in log.
* Method {@link #execute(Command, StreamConsumer, StreamConsumer, long)} is preferable,
public void stdOut_consumer_can_throw_exception() throws Exception {
Command command = Command.create(getScript("output")).setDirectory(workDir);
thrown.expect(CommandException.class);
- thrown.expectMessage("Error inside stdOut parser");
+ thrown.expectMessage("Error inside stdOut stream");
CommandExecutor.create().execute(command, BAD_CONSUMER, NOP_CONSUMER, 1000L);
}
public void stdErr_consumer_can_throw_exception() throws Exception {
Command command = Command.create(getScript("output")).setDirectory(workDir);
thrown.expect(CommandException.class);
- thrown.expectMessage("Error inside stdErr parser");
+ thrown.expectMessage("Error inside stdErr stream");
CommandExecutor.create().execute(command, NOP_CONSUMER, BAD_CONSUMER, 1000L);
}