136 exec(pb, verbose, false);
137 }
138
139
140 public static void exec(ProcessBuilder pb, boolean verbose,
141 boolean testForPresenseOnly) throws IOException {
142 exec(pb, verbose, testForPresenseOnly, null);
143 }
144
145 public static void exec(ProcessBuilder pb, boolean verbose,
146 boolean testForPresenseOnly, PrintStream consumer) throws IOException {
147 pb.redirectErrorStream(true);
148 Log.verbose("Running " + Arrays.toString(pb.command().toArray(new String[0]))
149 + (pb.directory() != null ? (" in " + pb.directory()) : ""));
150 Process p = pb.start();
151 InputStreamReader isr = new InputStreamReader(p.getInputStream());
152 BufferedReader br = new BufferedReader(isr);
153 String lineRead;
154 while ((lineRead = br.readLine()) != null) {
155 if (consumer != null) {
156 consumer.print(lineRead);
157 } else if (verbose) {
158 Log.info(lineRead);
159 } else {
160 Log.debug(lineRead);
161 }
162 }
163 try {
164 int ret = p.waitFor();
165 if (ret != 0 && !(testForPresenseOnly && ret != 127)) {
166 throw new IOException("Exec failed with code " + ret +
167 " command [" + Arrays.toString(pb.command().toArray(new String[0])) +
168 " in " + (pb.directory() != null ?
169 pb.directory().getAbsolutePath() : "unspecified directory"));
170 }
171 } catch (InterruptedException ex) {
172 }
173 }
174
175 //no good test if we are running pre-JRE7
176 //use heuristic approach
|
136 exec(pb, verbose, false);
137 }
138
139
140 public static void exec(ProcessBuilder pb, boolean verbose,
141 boolean testForPresenseOnly) throws IOException {
142 exec(pb, verbose, testForPresenseOnly, null);
143 }
144
145 public static void exec(ProcessBuilder pb, boolean verbose,
146 boolean testForPresenseOnly, PrintStream consumer) throws IOException {
147 pb.redirectErrorStream(true);
148 Log.verbose("Running " + Arrays.toString(pb.command().toArray(new String[0]))
149 + (pb.directory() != null ? (" in " + pb.directory()) : ""));
150 Process p = pb.start();
151 InputStreamReader isr = new InputStreamReader(p.getInputStream());
152 BufferedReader br = new BufferedReader(isr);
153 String lineRead;
154 while ((lineRead = br.readLine()) != null) {
155 if (consumer != null) {
156 consumer.print(lineRead + '\n');
157 } else if (verbose) {
158 Log.info(lineRead);
159 } else {
160 Log.debug(lineRead);
161 }
162 }
163 try {
164 int ret = p.waitFor();
165 if (ret != 0 && !(testForPresenseOnly && ret != 127)) {
166 throw new IOException("Exec failed with code " + ret +
167 " command [" + Arrays.toString(pb.command().toArray(new String[0])) +
168 " in " + (pb.directory() != null ?
169 pb.directory().getAbsolutePath() : "unspecified directory"));
170 }
171 } catch (InterruptedException ex) {
172 }
173 }
174
175 //no good test if we are running pre-JRE7
176 //use heuristic approach
|