Package nzilbb.util
Class Execution
- java.lang.Object
-
- nzilbb.util.Execution
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ExecutionaddStderrObserver(Consumer<String> observer)Builder-pattern method for adding a stderr observer.ExecutionaddStdoutObserver(Consumer<String> observer)Builder-pattern method for adding a stdout observer.Executionarg(String argument)Builder-style method for adding an argument toarguments.Executionenv(String variable, String value)Builder-style method for adding an environment variable toenvironmentVariables.Vector<String>getArguments()Getter forarguments: Command line arguments.LinkedHashMap<String,String>getEnvironmentVariables()Getter forenvironmentVariables: Environment variables.StringBuffergetError()Getter forerror: Text from stderrFilegetExe()Getter forexe: Executable file.booleangetFinished()Getter forfinished: Whether the execution has completed.StringBuffergetInput()Getter forinput: Text from stdoutProcessgetProcess()Getter forprocess: The executed process.booleangetRunning()Getter forrunning: Whether the execution is currently running.List<Consumer<String>>getStderrObservers()Getter forstderrObservers: Listeners for strings coming from stderr.InputStreamgetStdin()Getter forstdin: Stream to pass as 'stdin' to the process.List<Consumer<String>>getStdoutObservers()Getter forstdoutObservers: Listeners for strings coming from stdout.FilegetVenv()Getter forvenv: The directory of the Python virtual environment to execute in.booleangetVerbose()Getter forverbose: Whether to log verbose debug information to stdout or not.FilegetWorkingDirectory()Getter forworkingDirectory: The working directory for execution, or null for the current directory.voidrun()Runs the executable, monitors it, and returns when done.ExecutionsetArguments(Vector<String> newArguments)Setter forarguments: Command line arguments.ExecutionsetEnvironmentVariables(LinkedHashMap<String,String> newEnvironmentVariables)Setter forenvironmentVariables: Environment variables.ExecutionsetError(StringBuffer newError)Setter forerror: Text from stderrExecutionsetExe(File newExe)Setter forexe: Executable file.ExecutionsetExe(String command)Setter forexe: Executable file.ExecutionsetInput(StringBuffer newInput)Setter forinput: Text from stdoutExecutionsetProcess(Process newProcess)Setter forprocess: The executed process.ExecutionsetStdin(InputStream newStdin)Setter forstdin: Stream to pass as 'stdin' to the process.ExecutionsetVenv(File newVenv)Setter forvenv: The directory of the Python virtual environment to execute in.ExecutionsetVerbose(boolean newVerbose)Setter forverbose: Whether to log verbose debug information to stdout or not.ExecutionsetWorkingDirectory(File newWorkingDirectory)Setter forworkingDirectory: The working directory for execution, or null for the current directory.Stringstderr()Returns output printed to stderr.Executionstdin(File from)Where to get stdin data from.Executionstdin(InputStream from)Where to get stdin data from.Stringstdout()Returns output printed to stdout.static FileWhich(String command)Runs the "which" command to determine if a command is available.static FileWhich(String command, File venv)Runs the "which" command to determine if a command is available within a Python virtual environment.
-
-
-
Method Detail
-
getExe
public File getExe()
Getter forexe: Executable file.- Returns:
- Executable file.
-
setExe
public Execution setExe(File newExe)
Setter forexe: Executable file.- Parameters:
newExe- Executable file.
-
setExe
public Execution setExe(String command)
Setter forexe: Executable file.- Parameters:
command- Command.
-
getWorkingDirectory
public File getWorkingDirectory()
Getter forworkingDirectory: 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 forworkingDirectory: 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 forenvironmentVariables: Environment variables.- Returns:
- Environment variables.
-
setEnvironmentVariables
public Execution setEnvironmentVariables(LinkedHashMap<String,String> newEnvironmentVariables)
Setter forenvironmentVariables: Environment variables.- Parameters:
newEnvironmentVariables- Environment variables.
-
getVenv
public File getVenv()
Getter forvenv: The directory of the Python virtual environment to execute in.- Returns:
- The directory of the Python virtual environment to execute in.
-
setVenv
public Execution setVenv(File newVenv)
Setter forvenv: The directory of the Python virtual environment to execute in.- Parameters:
newVenv- The directory of the Python virtual environment to execute in.
-
getArguments
public Vector<String> getArguments()
Getter forarguments: Command line arguments.- Returns:
- Command line arguments.
-
setArguments
public Execution setArguments(Vector<String> newArguments)
Setter forarguments: Command line arguments.- Parameters:
newArguments- Command line arguments.
-
getProcess
public Process getProcess()
Getter forprocess: The executed process.- Returns:
- The executed process.
-
setProcess
public Execution setProcess(Process newProcess)
Setter forprocess: The executed process.- Parameters:
newProcess- The executed process.
-
getInput
public StringBuffer getInput()
Getter forinput: Text from stdout- Returns:
- Text from stdout
-
setInput
public Execution setInput(StringBuffer newInput)
Setter forinput: Text from stdout- Parameters:
newInput- Text from stdout
-
getError
public StringBuffer getError()
Getter forerror: Text from stderr- Returns:
- Text from stderr
-
setError
public Execution setError(StringBuffer newError)
Setter forerror: Text from stderr- Parameters:
newError- Text from stderr
-
getRunning
public boolean getRunning()
Getter forrunning: Whether the execution is currently running.- Returns:
- Whether the execution is currently running.
-
getFinished
public boolean getFinished()
Getter forfinished: Whether the execution has completed.- Returns:
- Whether the execution has completed.
-
getVerbose
public boolean getVerbose()
Getter forverbose: 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 forverbose: 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 forstdoutObservers: Listeners for strings coming from stdout.- Returns:
- Listeners for strings coming from stdout.
-
getStderrObservers
public List<Consumer<String>> getStderrObservers()
Getter forstderrObservers: Listeners for strings coming from stderr.- Returns:
- Listeners for strings coming from stderr.
-
getStdin
public InputStream getStdin()
Getter forstdin: Stream to pass as 'stdin' to the process.- Returns:
- Stream to pass as 'stdin' to the process.
-
setStdin
public Execution setStdin(InputStream newStdin)
Setter forstdin: Stream to pass as 'stdin' to the process.- Parameters:
newStdin- Stream to pass as 'stdin' to the process.
-
arg
public Execution arg(String argument)
Builder-style method for adding an argument toarguments.- Parameters:
argument- The argument to add.- Returns:
- A reference to this object.
-
stdin
public Execution stdin(InputStream from)
Where to get stdin data from.- Parameters:
from- A stream to read data from.- Returns:
- A reference to this object.
-
stdin
public Execution stdin(File from) throws FileNotFoundException
Where to get stdin data from.- Parameters:
from- A file to read data from.- Returns:
- A reference to this object.
- Throws:
FileNotFoundException- If the file doesn't exist.
-
env
public Execution env(String variable, String value)
Builder-style method for adding an environment variable toenvironmentVariables.- Parameters:
variable- The variable to add.value- The value for the variable.- Returns:
- A reference to this object.
-
addStdoutObserver
public Execution addStdoutObserver(Consumer<String> observer)
Builder-pattern method for adding a stdout observer.- Parameters:
observer-- Returns:
- This Execution.
-
addStderrObserver
public Execution addStderrObserver(Consumer<String> observer)
Builder-pattern method for adding a stderr observer.- Parameters:
observer-- Returns:
- This Execution.
-
run
public void run()
Runs the executable, monitors it, and returns when done.
-
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.
-
Which
public static File Which(String command, File venv)
Runs the "which" command to determine if a command is available within a Python virtual environment.- Parameters:
command- The command we want to location of.venv- The Python virtual environment to activate before running "which".- Returns:
- The executable file for the command, or null if it can't be identified.
-
-