[#BloombergLP-bsls-OutputRedirector]
= xref:BloombergLP.adoc[BloombergLP]::xref:BloombergLP/bsls.adoc[bsls]::OutputRedirector
:relfileprefix: ../../
:mrdocs:

This class provides a facility for redirecting `stdout` and `stderr` to temporary files, retrieving output from the respective temporary file and comparing the output to user&hyphen;supplied character buffers&period; An `OutputRedirector` object can be in an un&hyphen;redirected state or a redirected state&period; If the redirector is in a redirected state, it will redirect either `stdout` or `stderr`, but not both simultaneously&period; An `OutputRedirector` object has the concept of a scratch buffer, where output captured from the process&apos; `stdout` or `stderr` stream is stored when the `OutputRedirector` object is in the redirected state&period; Throughout this class, the term &quot;captured output&quot; refers to data that has been written to the `stdout` or `stderr` stream and is waiting to be loaded into the scratch buffer&period; Each time the `load` method is called, the scratch buffer is truncated, and the captured output is moved into the scratch buffer&period; When this is done, there is no longer any captured output&period;

== Synopsis

Declared in `&lt;bsls&lowbar;outputredirector&period;h&gt;`

[source,cpp,subs="verbatim,replacements,macros,-callouts"]
----
class OutputRedirector;
----

== Enums

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/OutputRedirector/Stream.adoc[`Stream`] 
| Identifies the standard stream redirected by this object&period;
|===


== Member Functions

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/OutputRedirector/2constructor.adoc[`OutputRedirector`]         [.small]#[constructor]#
| Create an `OutputRedirector` in an un&hyphen;redirected state, and with an empty scratch buffer&period; Upon a call to `enable`, this redirector will be responsible for redirecting the stream associated with the specified `which` to a temporary file&period; The behavior is undefined unless `which` is equal to `OutputRedirector&colon;&colon;e&lowbar;STDOUT&lowbar;STREAM` or `OutputRedirector&colon;&colon;e&lowbar;STDERR&lowbar;STREAM`&period;
| xref:BloombergLP/bsls/OutputRedirector/2destructor.adoc[`&#126;OutputRedirector`] [.small]#[destructor]#
| Destroy this `OutputRedirector` object&period; If the object is in a redirected state, the original stream will be restored to its initial target and the temporary file to which the stream was redirected will be deleted&period;
| xref:BloombergLP/bsls/OutputRedirector/clear.adoc[`clear`] 
| Reset the scratch buffer to empty&period; The behavior is undefined unless `enable` has been previously called successfully (after the latest call to `disable` if `disable` has been called successfully)&period;
| xref:BloombergLP/bsls/OutputRedirector/compare-0c.adoc[`compare`] 
| `compare` overloads
| xref:BloombergLP/bsls/OutputRedirector/disable.adoc[`disable`] 
| If the redirector is in a redirected state, restore the original target of the redirected stream and close the temporary buffer&period; If the redirector is not in a redirected state, this method is a no&hyphen;op&period; Calling this method invalidates all output in the temporary file, so a call to `load` after the next successful `enable` call will not load any output that was previously written to the file&period; This method does not clear the scratch buffer, so one may call `load` before calling `disable`, and the contents will be available after `disable` is called&period; If `disable` fails to disable the redirection, it will end the program by calling `std&colon;&colon;abort`&period;
| xref:BloombergLP/bsls/OutputRedirector/enable.adoc[`enable`] 
| If the `Stream` specified at construction was `e&lowbar;STDOUT&lowbar;STREAM`, redirect `stdout` to a temporary file&period; If the `Stream` specified at construction was `e&lowbar;STDERR&lowbar;STREAM`, redirect `stderr` to a temporary file&period; The temporary file to which the stream is redirected will be created the first time `enable` is called, and will be deleted when this object is destroyed&period; If `enable` fails to redirect either `stdout` or `stderr` it will end the program by calling `std&colon;&colon;abort`&period;
| xref:BloombergLP/bsls/OutputRedirector/getOutput.adoc[`getOutput`] 
| Return the address of the scratch buffer&period;
| xref:BloombergLP/bsls/OutputRedirector/isOutputReady.adoc[`isOutputReady`] 
| Return `true` if the captured output has been loaded into the scratch buffer, and `false` otherwise&period;
| xref:BloombergLP/bsls/OutputRedirector/isRedirecting.adoc[`isRedirecting`] 
| Return `true` if `stdout` or `stderr` has been successfully redirected, and `false` otherwise&period;
| xref:BloombergLP/bsls/OutputRedirector/load.adoc[`load`] 
| Read captured output into the scratch buffer&period; Return `true` if all captured output was successfully loaded, and `false` otherwise&period; Note that captured output is allowed to have zero length&period; The behavior is undefined unless `enable` has been previously called successfully (after the latest call to `disable`, if `disable` has been called successfully)&period;
| xref:BloombergLP/bsls/OutputRedirector/nonRedirectedStream.adoc[`nonRedirectedStream`] 
| Return the value of the global `stdout` or `stderr` corresponding to the stream that is not intended to be redirected by this object&period;
| xref:BloombergLP/bsls/OutputRedirector/outputSize.adoc[`outputSize`] 
| Return the number of bytes currently loaded into the scratch buffer&period;
| xref:BloombergLP/bsls/OutputRedirector/redirectedStream.adoc[`redirectedStream`] 
| Return the value of the global `stdout` or `stderr` corresponding to the stream that is intended to be redirected by this object&period;
| xref:BloombergLP/bsls/OutputRedirector/redirectedStreamId.adoc[`redirectedStreamId`] 
| Return `OutputRedirector&colon;&colon;e&lowbar;STDOUT&lowbar;STREAM` if this object is responsible for redirecting `stdout`, and `OutputRedirector&colon;&colon;e&lowbar;STDERR&lowbar;STREAM` if this object is responsible for redirecting `stderr`&period;
|===


== Static Data Members

[cols="1,4"]
|===
| Name| Description
| xref:BloombergLP/bsls/OutputRedirector/k_OUTPUT_REDIRECTOR_BUFFER_SIZE.adoc[`k&lowbar;OUTPUT&lowbar;REDIRECTOR&lowbar;BUFFER&lowbar;SIZE`] 
| The size of the buffer used to store the captured values loaded in the `stdout` and `stderr` error streams&period;
| xref:BloombergLP/bsls/OutputRedirector/k_PATH_BUFFER_SIZE.adoc[`k&lowbar;PATH&lowbar;BUFFER&lowbar;SIZE`] 
| The size of the buffer used to hold a file name&period;
|===



[.small]#Created with https://www.mrdocs.com[MrDocs]#
