public class ProcessStarter extends Object
This is the core class of the im4java-library where all the magic takes place. It does add some overhead compared to a direct call of ProcessBuilder, but you gain additional features like piping and asynchronous execution.
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE
Buffer size of process input-stream (used for reading the
output (sic!) of the process).
|
| Modifier | Constructor and Description |
|---|---|
protected |
ProcessStarter()
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addProcessEventListener(ProcessEventListener pListener)
Add a ProcessEventListener to this ProcessStarter.
|
void |
addProcessListener(ProcessListener pProcessListener)
Deprecated.
|
protected void |
finished(Exception pException)
Post-processing after the process has terminated with an
exception.
|
protected void |
finished(int pReturnCode)
Post-processing after the process has terminated.
|
static String |
getGlobalSearchPath()
Query the global (static) search path.
|
int |
getPID()
Query the process-id.
|
protected ProcessTask |
getProcessTask(LinkedList<String> pArgs)
Return a ProcessTask for future execution.
|
String |
getSearchPath()
Query the per object search path.
|
boolean |
isAsyncMode()
Query the async-execution mode.
|
void |
removeProcessEventListener(ProcessEventListener pListener)
Remove a ProcessEventListener from this ProcessStarter.
|
protected int |
run(LinkedList<String> pArgs)
Execute the command.
|
String |
searchForCmd(String pCmd,
String pPath)
Query the per object search path.
|
void |
setAsyncMode(boolean pAsyncMode)
Set the async-execution mode.
|
void |
setErrorConsumer(ErrorConsumer pErrorConsumer)
Set the ErrorConsumer for the stderr of the ProcessStarter.
|
static void |
setGlobalSearchPath(String pGlobalSearchPath)
Set the global (static) search path.
|
void |
setInputProvider(InputProvider pInputProvider)
Set the InputProvider for the ProcessStarter (if used as a pipe).
|
void |
setOutputConsumer(OutputConsumer pOutputConsumer)
Set the OutputConsumer for the ProcessStarter (if used as a pipe).
|
void |
setPID(int pPID)
Set the process-id of this ProcessStarter.
|
static void |
setPIDCounter(int pPID)
Set the process-id counter of the class.
|
void |
setSearchPath(String pSearchPath)
Set the per object search path.
|
public static final int BUFFER_SIZE
public void setInputProvider(InputProvider pInputProvider)
public void setOutputConsumer(OutputConsumer pOutputConsumer)
public void setErrorConsumer(ErrorConsumer pErrorConsumer)
public void addProcessEventListener(ProcessEventListener pListener)
pListener - the ProcessEventListener to addpublic void removeProcessEventListener(ProcessEventListener pListener)
pListener - the ProcessEventListener to removepublic void addProcessListener(ProcessListener pProcessListener)
addProcessEventListener(com.github.geko444.im4java.process.ProcessEventListener) insteadpProcessListener - the ProcessListener to addprotected int run(LinkedList<String> pArgs) throws IOException, InterruptedException, Exception
pArgs - arguments for ProcessBuilderIOExceptionInterruptedExceptionExceptionprotected ProcessTask getProcessTask(LinkedList<String> pArgs)
pArgs - arguments for ProcessBuilderpublic void setAsyncMode(boolean pAsyncMode)
pAsyncMode - the iAsyncMode to setpublic boolean isAsyncMode()
public static void setGlobalSearchPath(String pGlobalSearchPath)
pGlobalSearchPath - the global search pathpublic static String getGlobalSearchPath()
public void setSearchPath(String pSearchPath)
pSearchPath - the search pathpublic String getSearchPath()
public static void setPIDCounter(int pPID)
pPID - the process-idpublic void setPID(int pPID)
pPID - the process-idpublic int getPID()
protected void finished(int pReturnCode)
throws Exception
pReturnCode - the return-code of the processExceptionprotected void finished(Exception pException) throws Exception
Note that if this method throws an exception in asynchronous execution mode, the original exception is lost and not propagated to any ProcessEventListeners. Therefore, you should take care to fill in any exception and stack-trace information.
pException - the exception of the processExceptionpublic String searchForCmd(String pCmd, String pPath) throws IOException, FileNotFoundException
pCmd - the command to search forpPath - the search pathIOExceptionFileNotFoundExceptionCopyright © 2019. All rights reserved.