/** * Executes a process, waits for it to finish, prints the process output to stdout and returns the * process output. * * <p>The process will have exited before this method returns. * * @param pb The ProcessBuilder to execute. * @return The {@linkplain OutputAnalyzer} instance wrapping the process. */ public static OutputAnalyzer executeCommand(ProcessBuilder pb) throws Throwable { String cmdLine = pb.command().stream().collect(Collectors.joining(" ")); System.out.println("Command line: [" + cmdLine + "]"); OutputAnalyzer analyzer = ProcessTools.executeProcess(pb); System.out.println(analyzer.getOutput()); return analyzer; }
/** * Executes a process, waits for it to finish, prints the process output to stdout, and returns * the process output. * * <p>The process will have exited before this method returns. * * @param cmds The command line to execute. * @return The {@linkplain OutputAnalyzer} instance wrapping the process. */ public static OutputAnalyzer executeCommand(String... cmds) throws Throwable { String cmdLine = Arrays.stream(cmds).collect(Collectors.joining(" ")); System.out.println("Command line: [" + cmdLine + "]"); OutputAnalyzer analyzer = ProcessTools.executeProcess(cmds); System.out.println(analyzer.getOutput()); return analyzer; }