Skip to content

Commit

Permalink
throw exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sblantipodi committed Jan 9, 2025
1 parent cff35c5 commit 3208158
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/main/java/org/dpsoftware/NativeExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ public final class NativeExecutor {
*
* @param cmdToRunUsingArgs Command to run and args, in an array
* @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis)
* @param throwException throws exception on error
* @return A list of string containing the output, empty list if command does not exist
*/
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput) {
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput, boolean throwException) {
ArrayList<String> cmdOutput = new ArrayList<>();
try {
log.trace("Executing cmd={}", Arrays.stream(cmdToRunUsingArgs).toList());
Expand All @@ -86,14 +87,32 @@ public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutp
} else {
log.error("The command {} has exceeded the time limit and has been terminated.", Arrays.toString(cmdToRunUsingArgs));
process.destroy();
if (throwException) {
throw new RuntimeException();
}
}
}
} catch (Exception e) {
log.error(e.getMessage());
if (throwException) {
throw new RuntimeException(e);
}
}
return cmdOutput;
}

/**
* This is the real runner that executes command.
* Don't use this method directly and prefer the runNativeWaitForOutput() or runNativeNoWaitForOutput() shortcut.
*
* @param cmdToRunUsingArgs Command to run and args, in an array
* @param waitForOutput Example: If you need to exit the app you don't need to wait for the output or the app will not exit (millis)
* @return A list of string containing the output, empty list if command does not exist
*/
public static List<String> runNative(String[] cmdToRunUsingArgs, int waitForOutput) {
return runNative(cmdToRunUsingArgs, waitForOutput, false);
}

/**
* Spawn new Luciferin Native instance
*
Expand Down

0 comments on commit 3208158

Please sign in to comment.