-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathacolyte.java
More file actions
47 lines (36 loc) · 1.37 KB
/
acolyte.java
File metadata and controls
47 lines (36 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class acolyte {
public static final String JAR_NAME = "Acolyte-1.0-SNAPSHOT.jar";
public static void main(String[] args) throws Exception {
String os = System.getProperty("os.name").toLowerCase();
boolean isWindows = os.contains("win");
List<String> command = new ArrayList<>();
if (isWindows) {
command.add("cmd.exe");
command.add("/c");
} else {
command.add("sh");
command.add("-c");
}
StringBuilder fullCommand = new StringBuilder("java -jar " + JAR_NAME);
if (args.length > 0) {
fullCommand.append(" ").append(String.join(" ", args));
}
command.add(fullCommand.toString());
ProcessBuilder builder = new ProcessBuilder(command);
builder.directory(new File(System.getProperty("user.dir")));
builder.redirectErrorStream(true);
Process process = builder.start();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}
int exitCode = process.waitFor();
}
}