MCPcopy Create free account
hub / github.com/OpenEndedGroup/Field2 / go

Method go

src/main/java/field/utility/SimpleCommand.java:10–32  ·  view source on GitHub ↗
(File dir, String command, String... args)

Source from the content-addressed store, hash-verified

8public 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

Callers 1

revealInFinderMethod · 0.95

Calls 7

toMethod · 0.80
linesMethod · 0.80
getInputStreamMethod · 0.65
acceptMethod · 0.65
addMethod · 0.45
startMethod · 0.45
readLineMethod · 0.45

Tested by

no test coverage detected