Package org.apache.commons.exec
Class PumpStreamHandler
java.lang.Object
org.apache.commons.exec.PumpStreamHandler
- All Implemented Interfaces:
ExecuteStreamHandler
Copies standard output and error of sub-processes to standard output and error of the parent process. If output or error stream are set to null, any feedback
from that stream will be lost.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newPumpStreamHandler.PumpStreamHandler(OutputStream allOutputStream) Constructs a newPumpStreamHandler.PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream) Constructs a newPumpStreamHandler.PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream, InputStream inputStream) Constructs a newPumpStreamHandler. -
Method Summary
Modifier and TypeMethodDescriptionvoidSets theInputStreamfrom which to read the standard error of the process.voidSets theOutputStreamby means of which input can be sent to the process.voidSets theInputStreamfrom which to read the standard output of the process.voidsetStopTimeout(long timeout) Deprecated.voidsetStopTimeout(Duration timeout) Sets maximum time to wait until output streams are exhausted whenstop()was called.voidstart()Starts theThreads.voidstop()Stops pumping the streams.
-
Constructor Details
-
PumpStreamHandler
public PumpStreamHandler()Constructs a newPumpStreamHandler. -
PumpStreamHandler
Constructs a newPumpStreamHandler.- Parameters:
allOutputStream- the output/errorOutputStream. TheOutputStreamimplementation must be thread-safe because the output and error reader threads will concurrently write to it.
-
PumpStreamHandler
Constructs a newPumpStreamHandler.If the same
OutputStreaminstance is used for output and error, then it must be thread-safe because the output and error reader threads will concurrently write to it.- Parameters:
outputStream- the outputOutputStream.errorOutputStream- the errorOutputStream.
-
PumpStreamHandler
public PumpStreamHandler(OutputStream outputStream, OutputStream errorOutputStream, InputStream inputStream) Constructs a newPumpStreamHandler.If the same
OutputStreaminstance is used for output and error, then it must be thread-safe because the output and error reader threads will concurrently write to it.- Parameters:
outputStream- the outputOutputStream.errorOutputStream- the errorOutputStream.inputStream- the inputInputStream.
-
-
Method Details
-
setProcessErrorStream
Sets theInputStreamfrom which to read the standard error of the process.- Specified by:
setProcessErrorStreamin interfaceExecuteStreamHandler- Parameters:
is- theInputStream.
-
setProcessInputStream
Sets theOutputStreamby means of which input can be sent to the process.- Specified by:
setProcessInputStreamin interfaceExecuteStreamHandler- Parameters:
os- theOutputStream.
-
setProcessOutputStream
Sets theInputStreamfrom which to read the standard output of the process.- Specified by:
setProcessOutputStreamin interfaceExecuteStreamHandler- Parameters:
is- theInputStream.
-
setStopTimeout
Sets maximum time to wait until output streams are exhausted whenstop()was called.- Parameters:
timeout- timeout or zero to wait forever (default).- Since:
- 1.4.0
-
setStopTimeout
Deprecated.Sets maximum time to wait until output streams are exhausted whenstop()was called.- Parameters:
timeout- timeout in milliseconds or zero to wait forever (default).
-
start
public void start()Starts theThreads.- Specified by:
startin interfaceExecuteStreamHandler
-
stop
Stops pumping the streams. When a timeout is specified it is not guaranteed that the pumper threads are cleanly terminated.- Specified by:
stopin interfaceExecuteStreamHandler- Throws:
IOException- thrown when an I/O exception occurs.
-
setStopTimeout(Duration).