Package aQute.lib.redirect
Class Redirect
java.lang.Object
aQute.lib.redirect.Redirect
Utility to redirect the stdin/stdout/stderr when running a command
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate boolean
private boolean
private Capture
private Capture
private final OutputStream
private final InputStream
private final OutputStream
-
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.private PrintStream
build
(PrintStream original, OutputStream redirect, Capture capture) Capture stderr during an apply.Capture stdout during an apply.
-
Field Details
-
stdin
-
stdout
-
stderr
-
captureStdout
private boolean captureStdout -
captureStderr
private boolean captureStderr -
cstdout
-
cstderr
-
-
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 & 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
-
build
-
getStderr
-
getStdout
-
getContent
-