| 9 | |
| 10 | public class OSExecute { |
| 11 | public static void command(String command) { |
| 12 | boolean err = false; |
| 13 | try { |
| 14 | Process process = new ProcessBuilder( |
| 15 | command.split(" ")).start(); |
| 16 | try( |
| 17 | BufferedReader results = new BufferedReader( |
| 18 | new InputStreamReader( |
| 19 | process.getInputStream())); |
| 20 | BufferedReader errors = new BufferedReader( |
| 21 | new InputStreamReader( |
| 22 | process.getErrorStream())) |
| 23 | ) { |
| 24 | results.lines() |
| 25 | .forEach(System.out::println); |
| 26 | err = errors.lines() |
| 27 | .peek(System.err::println) |
| 28 | .count() > 0; |
| 29 | } |
| 30 | } catch(IOException e) { |
| 31 | throw new RuntimeException(e); |
| 32 | } |
| 33 | if(err) |
| 34 | throw new OSExecuteException( |
| 35 | "Errors executing " + command); |
| 36 | } |
| 37 | } |