Modifier and Type | Class and Description |
---|---|
static class |
Execution.OutputListener
Reports output received from an external process.
|
Constructor and Description |
---|
Execution(String[] commandArray,
Cancelable cancelable,
Execution.OutputListener outputListener,
InputStream inputStream,
boolean tryToEmulateTerminal)
Constructs an Execution object that represents an
execution of an external program.
|
Execution(String[] commandArray,
Cancelable cancelable,
Execution.OutputListener outputListener,
String input,
boolean tryToEmulateTerminal)
Constructs an Execution object that represents an
execution of an external program.
|
Modifier and Type | Method and Description |
---|---|
int |
execute()
Starts execution of the external program represented by this object.
|
int |
execute(Map<String,String> environment)
Starts execution of the external program represented by this object.
|
boolean |
isEmulatingTerminal()
Return true if this process is being executed by emulating a terminal.
|
protected boolean |
isSafeToKillOutReadThread()
Tells
Execution whether it is safe to end the thread which reads stdout from the process. |
void |
setWorkingDirectory(String workingDirectory)
Set the working directory of the external process.
|
protected void |
setWritingFinished()
Called when stdout has finished being read.
|
boolean |
wasKilledByGeneious()
Returns true if the process was terminated by Geneious due to the
Cancelable passed
to the constructor requesting that the process execution be canceled. |
public Execution(String[] commandArray, Cancelable cancelable, Execution.OutputListener outputListener, String input, boolean tryToEmulateTerminal)
execute()
.commandArray
- The components of the command line, the first of which is the path of the program to execute.cancelable
- A callback which can be queried by the Execution object to determine whether
termination of the external program has been requested. Must not be null, but may be ProgressListener.EMPTY
.outputListener
- A callback that is notified when the external program produces output. If
progress is to be reported (in this case cancelable was probably derived from
a ProgressListener
) then it is recommended that outputListener
internally stores a copy of that ProgressListener and calls it.input
- The input to provide on the external program's stdin.
May be "" or a String variable with value null in which case no input will be provided to stdin.
A null constant would be ambiguous and cause a compile time errortryToEmulateTerminal
- true if we should try to emulate a terminal (to create an unbuffered stdout/stderr on Windows). Even if this parameter is true, the Execution implementation may choose to ignore it on unsupported operating systems. See isEmulatingTerminal()
.public Execution(String[] commandArray, Cancelable cancelable, Execution.OutputListener outputListener, InputStream inputStream, boolean tryToEmulateTerminal)
execute()
.commandArray
- The components of the command line, the first of which is the path of the program to execute.cancelable
- A callback which can be queried by the Execution object to determine whether
termination of the external program has been requested. Must not be null, but may be ProgressListener.EMPTY
.outputListener
- A callback that is notifed when the external program produces output. If
progress is to be reported (in this case cancelable was probably derived from
a ProgressListener
) then it is recommended that outputListener
internally stores a copy of that ProgressListener and calls it.inputStream
- The input to provide on the external program's stdin.
May be an InputStream variable with null value in which case no input will be provided to stdin.
A null constant would be ambiguous and cause a compile time errortryToEmulateTerminal
- true if we should try to emulate a terminal (to create an unbuffered stdout/stderr on Windows). Even if this parameter is true, the Execution implementation may choose to ignore it on unsupported operating systems. See isEmulatingTerminal()
.protected void setWritingFinished()
super.setWritingFinished
protected boolean isSafeToKillOutReadThread()
Execution
whether it is safe to end the thread which reads stdout from the process. The thread
will be kept alive as long as this returns false. By default this method returns true when the process has finished
but it can be overridden to keep the thread alive longer. This method should not perform any clean up because it
is called throughout execution. Override setWritingFinished()
instead for this purpose. Overriding
methods should also check super.isSafeToKillOutReadThread
.public int execute() throws InterruptedException, IOException
execute(java.util.Map)
with an empty map.InterruptedException
- If such an exception is thrown when trying to wait for the
external program to finish (see Process.waitFor()
or waiting for the
threads that poll the process' stdout/stderr to die (see Thread.join()
).IOException
- If such an exception occurs while trying to execute the external programpublic int execute(Map<String,String> environment) throws InterruptedException, IOException
environment
- A map containing the environment variables the process is to be run with.
See ProcessBuilder.environment()
InterruptedException
- If such an exception is thrown when trying to wait for the
external program to finish (see Process.waitFor()
or waiting for the
threads that poll the process' stdout/stderr to die (see Thread.join()
).IOException
- If such an exception occurs while trying to execute the external programpublic void setWorkingDirectory(String workingDirectory)
execute()
.workingDirectory
- the working directory to set.public boolean wasKilledByGeneious()
Cancelable
passed
to the constructor requesting that the process execution be canceled.Cancelable
passed
to the constructor requesting that the process execution be canceled.public boolean isEmulatingTerminal()