/** * Executes a process and returns the process output and exit code. */ public static ProcessResult run(Process process) throws IOException, InterruptedException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), baos, "out>"); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), baos, "err>"); outputGobbler.start(); errorGobbler.start(); int result = process.waitFor(); outputGobbler.waitFor(); errorGobbler.waitFor(); return new ProcessResult(result, baos.toString()); }
/** * Executes a process and returns the process output and exit code. */ public static ProcessResult run(final Process process) throws InterruptedException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), baos, OUTPUT_PREFIX); final StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), baos, ERROR_PREFIX); outputGobbler.start(); errorGobbler.start(); final int result = process.waitFor(); outputGobbler.waitFor(); errorGobbler.waitFor(); return new ProcessResult(result, baos.toString()); }
StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), out, outPrefix); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), err, errPrefix); outputGobbler.start(); errorGobbler.start(); outputGobbler.waitFor(); errorGobbler.waitFor();
/** * Executes a process and returns the process output and exit code. */ public static ProcessResult run(final Process process) throws InterruptedException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), baos, OUTPUT_PREFIX); final StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), baos, ERROR_PREFIX); outputGobbler.start(); errorGobbler.start(); final int result = process.waitFor(); outputGobbler.waitFor(); errorGobbler.waitFor(); return new ProcessResult(result, baos.toString()); }
StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), out, outPrefix); StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), err, errPrefix); outputGobbler.start(); errorGobbler.start(); outputGobbler.waitFor(); errorGobbler.waitFor();