Package nzilbb.util

Class Execution

  • All Implemented Interfaces:
    Runnable

    public class Execution
    extends Object
    implements Runnable
    Manages the execution of an external program, ensuring that streams are processed, etc.
    Author:
    Robert Fromont robert@fromont.net.nz
    • Constructor Detail

      • Execution

        public Execution()
        Default constructor.
      • Execution

        public Execution​(File exe,
                         Vector<String> arguments)
        Constructor from attributes.
    • Method Detail

      • getExe

        public File getExe()
        Getter for exe: Executable file.
        Returns:
        Executable file.
      • setExe

        public Execution setExe​(File newExe)
        Setter for exe: Executable file.
        Parameters:
        newExe - Executable file.
      • setExe

        public Execution setExe​(String command)
        Setter for exe: Executable file.
        Parameters:
        command - Command.
      • getWorkingDirectory

        public File getWorkingDirectory()
        Getter for workingDirectory: The working directory for execution, or null for the current directory.
        Returns:
        The working directory for execution, or null for the current directory.
      • setWorkingDirectory

        public Execution setWorkingDirectory​(File newWorkingDirectory)
        Setter for workingDirectory: The working directory for execution, or null for the current directory.
        Parameters:
        newWorkingDirectory - The working directory for execution, or null for the current directory.
      • getEnvironmentVariables

        public LinkedHashMap<String,​String> getEnvironmentVariables()
        Getter for environmentVariables: Environment variables.
        Returns:
        Environment variables.
      • setEnvironmentVariables

        public Execution setEnvironmentVariables​(LinkedHashMap<String,​String> newEnvironmentVariables)
        Setter for environmentVariables: Environment variables.
        Parameters:
        newEnvironmentVariables - Environment variables.
      • getArguments

        public Vector<String> getArguments()
        Getter for arguments: Command line arguments.
        Returns:
        Command line arguments.
      • setArguments

        public Execution setArguments​(Vector<String> newArguments)
        Setter for arguments: Command line arguments.
        Parameters:
        newArguments - Command line arguments.
      • getProcess

        public Process getProcess()
        Getter for process: The executed process.
        Returns:
        The executed process.
      • setProcess

        public Execution setProcess​(Process newProcess)
        Setter for process: The executed process.
        Parameters:
        newProcess - The executed process.
      • getInput

        public StringBuffer getInput()
        Getter for input: Text from stdout
        Returns:
        Text from stdout
      • setInput

        public Execution setInput​(StringBuffer newInput)
        Setter for input: Text from stdout
        Parameters:
        newInput - Text from stdout
      • getError

        public StringBuffer getError()
        Getter for error: Text from stderr
        Returns:
        Text from stderr
      • setError

        public Execution setError​(StringBuffer newError)
        Setter for error: Text from stderr
        Parameters:
        newError - Text from stderr
      • getRunning

        public boolean getRunning()
        Getter for running: Whether the execution is currently running.
        Returns:
        Whether the execution is currently running.
      • getFinished

        public boolean getFinished()
        Getter for finished: Whether the execution has completed.
        Returns:
        Whether the execution has completed.
      • getVerbose

        public boolean getVerbose()
        Getter for verbose: Whether to log verbose debug information to stdout or not.
        Returns:
        Whether to log verbose debug information to stdout or not.
      • setVerbose

        public Execution setVerbose​(boolean newVerbose)
        Setter for verbose: Whether to log verbose debug information to stdout or not.
        Parameters:
        newVerbose - Whether to log verbose debug information to stdout or not.
      • getStdoutObservers

        public List<Consumer<String>> getStdoutObservers()
        Getter for stdoutObservers: Listeners for strings coming from stdout.
        Returns:
        Listeners for strings coming from stdout.
      • getStderrObservers

        public List<Consumer<String>> getStderrObservers()
        Getter for stderrObservers: Listeners for strings coming from stderr.
        Returns:
        Listeners for strings coming from stderr.
      • arg

        public Execution arg​(String argument)
        Builder-style method for adding an argument to arguments.
        Parameters:
        argument - The argument to add.
        Returns:
        A reference to this object.
      • env

        public Execution env​(String variable,
                             String value)
        Builder-style method for adding an environment variable to environmentVariables.
        Parameters:
        variable - The variable to add.
        value - The value for the variable.
        Returns:
        A reference to this object.
      • run

        public void run()
        Runs the executable, monitors it, and returns when done.
        Specified by:
        run in interface Runnable
      • stdout

        public String stdout()
        Returns output printed to stdout.
        Returns:
        Output printed to stdout.
        See Also:
        getInput()
      • stderr

        public String stderr()
        Returns output printed to stderr.
        Returns:
        Output printed to stderr.
        See Also:
        getError()
      • Which

        public static File Which​(String command)
        Runs the "which" command to determine if a command is available.
        Parameters:
        command - The command we want to location of.
        Returns:
        The executable file for the command, or null if it can't be identified.