Making sure the streams are closed.
*/
package com.blackducksoftware.integration.hub.detect.util.executable
+import org.apache.commons.io.IOUtils
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
@@ -45,10 +46,14 @@ public class ExecutableRunner {
final ProcessBuilder processBuilder = executable.createProcessBuilder()
final Process process = processBuilder.start()
- ExecutableStreamThread standardOutputThread = new ExecutableStreamThread(process.getInputStream(), logger);
+ InputStream standardOutputStream = process.getInputStream();
+ InputStream standardErrorStream = process.getErrorStream();
+
+ try {
+ ExecutableStreamThread standardOutputThread = new ExecutableStreamThread(standardOutputStream, logger);
standardOutputThread.start();
- ExecutableStreamThread errorOutputThread = new ExecutableStreamThread(process.getErrorStream(), logger);
+ ExecutableStreamThread errorOutputThread = new ExecutableStreamThread(standardErrorStream, logger);
errorOutputThread.start();
int returnCode = process.waitFor();
@@ -61,6 +66,10 @@ public class ExecutableRunner {
final ExecutableOutput output = new ExecutableOutput(standardOutput, errorOutput)
return output
+ } finally {
+ IOUtils.closeQuietly(standardOutputStream);
+ IOUtils.closeQuietly(standardErrorStream);
+ }
} catch (final Exception e) {
throw new ExecutableRunnerException(e)
}
