Package aQute.lib.redirect
Class Redirect
java.lang.Object
aQute.lib.redirect.Redirect
Utility to redirect the stdin/stdout/stderr when running a command
-
Constructor Summary
ConstructorsConstructorDescriptionRedirect
(InputStream stdin, OutputStream stdout, OutputStream stderr) Create a stdio redirectorRedirect
(OutputStream stdout, OutputStream stderr) Create a stdio redirector without any inputRedirect
(String stdin, OutputStream stdout, OutputStream stderr) Create a stdio redirector -
Method Summary
Modifier and TypeMethodDescription<R> R
apply
(SupplierWithException<R> f) Call the supplier and return the result.Capture stderr during an apply.Capture stdout during an apply.
-
Constructor Details
-
Redirect
Create a stdio redirector- Parameters:
stdin
- the stdin read from or null for System.instdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
Redirect
Create a stdio redirector- Parameters:
stdin
- the stdin read from or null for System.instdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
Redirect
Create a stdio redirector without any input- Parameters:
stdout
- the stdout to write to or null for System.outstderr
- the stderr to write to or null for System.err
-
-
Method Details
-
captureStdout
Capture stdout during an apply. Every apply will be captured seperately.- Returns:
- this
-
captureStderr
Capture stderr during an apply. Every apply will be captured seperately.- Returns:
- this
-
apply
Call the supplier and return the result. While the supplier is active, the System streams are redirected as instructed by the constructor. Redirection invalid input: '&' capture will only take place on the current thread. The original state will be introduced afterwards.Although the system streams are redirected, the original output streams are still written to.
- Type Parameters:
R
- the type for the supplier- Parameters:
f
- the supplier- Returns:
- the return of the supplier.
- Throws:
Exception
-
getStderr
-
getStdout
-
getContent
-