Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 40 additions & 14 deletions cli/src/main/java/dev/starfix/Starfix.java
Original file line number Diff line number Diff line change
Expand Up @@ -285,22 +285,48 @@ public static void gitClone(Path directory, String originUrl) throws IOException

public static String runCommand(Path directory, String... command) throws IOException, InterruptedException {
// Function to Run Commands using Process Builder
ProcessResult presult;
try {
System.out.println("Running " + String.join(" ", command));
presult = new ProcessExecutor().command(command).redirectOutput(System.out).redirectErrorStream(true).readOutput(true)
.execute();
} catch (TimeoutException e) {
throw new RuntimeException("Error running command", e);
}
ProcessResult presult;

if (isWindows()) {
try{
System.out.println("Running " + String.join(" ", command));
String[] commandLineArgs = new String[2 + command.length];
commandLineArgs[0] = "CMD";
commandLineArgs[1] = "/C";
System.arraycopy(command, 0, commandLineArgs, 2, command.length);
presult = new ProcessExecutor().command(commandLineArgs).redirectOutput(System.out).redirectErrorStream(true).readOutput(true)
.execute();
} catch (Exception e) {
throw new RuntimeException("Error running command", e);
}

int exit = presult.getExitValue();
if (exit!=0) {
throw new AssertionError(
String.format("runCommand %s in %s returned %d", Arrays.toString(command), directory, exit));
}
int exit = presult.getExitValue();
if (exit!=0) {
throw new AssertionError(
String.format("runCommand %s in %s returned %d", Arrays.toString(command), directory, exit));
}

return presult.outputUTF8().replaceAll("\"","");

} else{

try {
System.out.println("Running " + String.join(" ", command));
presult = new ProcessExecutor().command(command).redirectOutput(System.out).redirectErrorStream(true).readOutput(true)
.execute();
} catch (TimeoutException e) {
throw new RuntimeException("Error running command", e);
}

int exit = presult.getExitValue();
if (exit!=0) {
throw new AssertionError(
String.format("runCommand %s in %s returned %d", Arrays.toString(command), directory, exit));
}

return presult.outputUTF8();

return presult.outputUTF8();
}
}

public static class CloneUrl{
Expand Down