Package aQute.lib.redirect
Class Redirect
- java.lang.Object
-
- aQute.lib.redirect.Redirect
-
public class Redirect extends java.lang.ObjectUtility to redirect the stdin/stdout/stderr when running a command
-
-
Field Summary
Fields Modifier and Type Field Description private booleancaptureStderrprivate booleancaptureStdoutprivate Capturecstderrprivate Capturecstdoutprivate java.io.OutputStreamstderrprivate java.io.InputStreamstdinprivate java.io.OutputStreamstdout
-
Constructor Summary
Constructors Constructor Description Redirect(java.io.InputStream stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)Create a stdio redirectorRedirect(java.io.OutputStream stdout, java.io.OutputStream stderr)Create a stdio redirector without any inputRedirect(java.lang.String stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)Create a stdio redirector
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> Rapply(SupplierWithException<R> f)Call the supplier and return the result.private java.io.PrintStreambuild(java.io.PrintStream original, java.io.OutputStream redirect, Capture capture)RedirectcaptureStderr()Capture stderr during an apply.RedirectcaptureStdout()Capture stdout during an apply.java.lang.StringgetContent()java.lang.StringgetStderr()java.lang.StringgetStdout()
-
-
-
Field Detail
-
stdin
private final java.io.InputStream stdin
-
stdout
private final java.io.OutputStream stdout
-
stderr
private final java.io.OutputStream stderr
-
captureStdout
private boolean captureStdout
-
captureStderr
private boolean captureStderr
-
cstdout
private Capture cstdout
-
cstderr
private Capture cstderr
-
-
Constructor Detail
-
Redirect
public Redirect(java.io.InputStream stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)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
public Redirect(java.lang.String stdin, java.io.OutputStream stdout, java.io.OutputStream stderr)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
public Redirect(java.io.OutputStream stdout, java.io.OutputStream stderr)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 Detail
-
captureStdout
public Redirect captureStdout()
Capture stdout during an apply. Every apply will be captured seperately.- Returns:
- this
-
captureStderr
public Redirect captureStderr()
Capture stderr during an apply. Every apply will be captured seperately.- Returns:
- this
-
apply
public <R> R apply(SupplierWithException<R> f) throws java.lang.Exception
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:
java.lang.Exception
-
build
private java.io.PrintStream build(java.io.PrintStream original, java.io.OutputStream redirect, Capture capture)
-
getStderr
public java.lang.String getStderr()
-
getStdout
public java.lang.String getStdout()
-
getContent
public java.lang.String getContent()
-
-