All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.laskowski.shell.task.DefaultShellTask Maven / Gradle / Ivy

Go to download

Library to launch .bat and .sh scripts of your choice with different configurations. Allows you to read tasks and services output from terminal

There is a newer version: 2.0.6.1
Show newest version
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