Package aQute.lib.redirect
Class Redirect
- java.lang.Object
-
- aQute.lib.redirect.Redirect
-
public class Redirect extends java.lang.Object
Utility to redirect the stdin/stdout/stderr when running a command
-
-
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> R
apply(SupplierWithException<R> f)
Call the supplier and return the result.Redirect
captureStderr()
Capture stderr during an apply.Redirect
captureStdout()
Capture stdout during an apply.java.lang.String
getContent()
java.lang.String
getStderr()
java.lang.String
getStdout()
-
-
-
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
-
getStderr
public java.lang.String getStderr()
-
getStdout
public java.lang.String getStdout()
-
getContent
public java.lang.String getContent()
-
-