238 Result run(String cmd) throws Exception { |
238 Result run(String cmd) throws Exception { |
239 String[] cmds = cmd.split(" +"); |
239 String[] cmds = cmd.split(" +"); |
240 cmds[0] = cmdPath.resolve(cmds[0]).toString(); |
240 cmds[0] = cmdPath.resolve(cmds[0]).toString(); |
241 ProcessBuilder pb = new ProcessBuilder(cmds); |
241 ProcessBuilder pb = new ProcessBuilder(cmds); |
242 pb.directory(mrjar.toFile()); |
242 pb.directory(mrjar.toFile()); |
243 Process p = pb.start(); |
243 Process p = null; |
244 p.waitFor(10, TimeUnit.SECONDS); |
244 try { |
245 String out; |
245 p = pb.start(); |
246 try (InputStream is = p.getInputStream()) { |
246 p.waitFor(); |
247 out = new String(is.readAllBytes()); |
247 |
248 } |
248 String out; |
249 String err; |
249 try (InputStream is = p.getInputStream()) { |
250 try (InputStream is = p.getErrorStream()) { |
250 out = new String(is.readAllBytes()); |
251 err = new String(is.readAllBytes()); |
251 } |
252 } |
252 String err; |
253 return new Result(cmd, p.exitValue(), out, err); |
253 try (InputStream is = p.getErrorStream()) { |
|
254 err = new String(is.readAllBytes()); |
|
255 } |
|
256 return new Result(cmd, p.exitValue(), out, err); |
|
257 } catch (Throwable t) { |
|
258 if (p != null) { |
|
259 p.destroyForcibly().waitFor(); |
|
260 } |
|
261 throw t; |
|
262 } |
254 } |
263 } |
255 |
264 |
256 void checkResult(Result r) throws Exception { |
265 void checkResult(Result r) throws Exception { |
257 System.out.println(r.cmd); |
266 System.out.println(r.cmd); |
258 System.out.println(r.out); |
267 System.out.println(r.out); |