Skip to content
Open
Changes from 7 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
50 changes: 36 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,44 @@ 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));
presult = new ProcessExecutor().command("CMD", "/C", command[0], command[1]).redirectOutput(System.out).redirectErrorStream(true).readOutput(true)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you assuming that commands array will be of max size 2. can't there be more args than that ?
Infact there itself look at the gitClone Function which is calling run command with how many args:
runCommand(directory.getParent(), "git", "clone", originUrl, directory.toString());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my mistake. its done now I think.

.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