MCPcopy Index your code
hub / github.com/BruceEckel/OnJava8-Examples / command

Method command

onjava/OSExecute.java:11–36  ·  view source on GitHub ↗
(String command)

Source from the content-addressed store, hash-verified

9
10public 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}

Callers 1

mainMethod · 0.95

Calls 4

splitMethod · 0.80
peekMethod · 0.80
startMethod · 0.45
countMethod · 0.45

Tested by

no test coverage detected