io.github.laskowski.shell.task.DefaultShellTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of shell-commander Show documentation
Show all versions of shell-commander Show documentation
Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal
package io.github.laskowski.shell.task;
import io.github.laskowski.shell.script.DefaultScriptInfoProvider;
import io.github.laskowski.shell.script.Script;
import io.github.laskowski.shell.ShellArguments;
import io.github.rafal.laskowski.wait.Wait;
import java.io.IOException;
public abstract class DefaultShellTask implements ShellTask {
private static final ShellArguments SHELL_ARGUMENTS = DefaultScriptInfoProvider.getInstance().getShellArguments();
private volatile Process process;
@Override
public void start() {
Script script = getScript();
ProcessBuilder processBuilder = new ProcessBuilder(SHELL_ARGUMENTS.getExecutor(), SHELL_ARGUMENTS.getExecutionArguments(), script.getFile().getAbsolutePath());
try {
process = processBuilder.start();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public void stop() {
process.destroy();
}
@Override
public Process getProcess() {
new Wait().withMessage("Failed to wait until Process is not null").until(() -> process != null);
return process;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy