(File dir, String command, String... args)
| 8 | public class SimpleCommand { |
| 9 | |
| 10 | static public Triple<String, String, Integer> go(File dir, String command, String... args) throws IOException, InterruptedException { |
| 11 | File t1 = File.createTempFile("field", ".out.txt"); |
| 12 | t1.deleteOnExit(); |
| 13 | File t2 = File.createTempFile("field", ".out.txt"); |
| 14 | t2.deleteOnExit(); |
| 15 | |
| 16 | ArrayList<String> all = new ArrayList<>(args.length + 1); |
| 17 | all.add(command); |
| 18 | for (String s : args) |
| 19 | all.add(s); |
| 20 | |
| 21 | ProcessBuilder p = new ProcessBuilder(all); |
| 22 | p.directory(dir); |
| 23 | p.redirectOutput(ProcessBuilder.Redirect.to(t1)); |
| 24 | p.redirectError(ProcessBuilder.Redirect.to(t2)); |
| 25 | |
| 26 | int ret = p.start() |
| 27 | .waitFor(); |
| 28 | |
| 29 | return new Triple<>(Files.lines(t1.toPath()) |
| 30 | .reduce("", (a, b) -> a + "\n" + b), Files.lines(t2.toPath()) |
| 31 | .reduce("", (a, b) -> a + "\n" + b), ret); |
| 32 | } |
| 33 | |
| 34 | static public Integer go(File dir, Consumer<String> output, String command, String... args) throws IOException, InterruptedException { |
| 35 |
no test coverage detected