The requirements from such a library are:
- Execute the process asynchronously.
- Ability to abort the process execution.
- Ability to wait for process completion.
- On process output notifications.
- Ability to kill the process in case it hung.
- Get the process exit code.
Here is the method signature we expose:
- It returns a Future<Long>. This covers section 1,2,3,6.
- Instance of ProcessExecutorHandler is passed to the function. This instance is actually a listener for any process output. This covers section 4 in our requirement.
- Last but not least you supply a timeout. If the process execution takes more than said timeout you assume the process hung and you will end it. In that case the error code returned by the process will be -999.