[#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‐supplied character buffers. An `OutputRedirector` object can be in an un‐redirected state or a redirected state. If the redirector is in a redirected state, it will redirect either `stdout` or `stderr`, but not both simultaneously. An `OutputRedirector` object has the concept of a scratch buffer, where output captured from the process' `stdout` or `stderr` stream is stored when the `OutputRedirector` object is in the redirected state. Throughout this class, the term "captured output" refers to data that has been written to the `stdout` or `stderr` stream and is waiting to be loaded into the scratch buffer. Each time the `load` method is called, the scratch buffer is truncated, and the captured output is moved into the scratch buffer. When this is done, there is no longer any captured output. == Synopsis Declared in `<bsls_outputredirector.h>` [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. |=== == Member Functions [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bsls/OutputRedirector/2constructor.adoc[`OutputRedirector`] [.small]#[constructor]# | Create an `OutputRedirector` in an un‐redirected state, and with an empty scratch buffer. Upon a call to `enable`, this redirector will be responsible for redirecting the stream associated with the specified `which` to a temporary file. The behavior is undefined unless `which` is equal to `OutputRedirector::e_STDOUT_STREAM` or `OutputRedirector::e_STDERR_STREAM`. | xref:BloombergLP/bsls/OutputRedirector/2destructor.adoc[`~OutputRedirector`] [.small]#[destructor]# | Destroy this `OutputRedirector` object. 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. | xref:BloombergLP/bsls/OutputRedirector/clear.adoc[`clear`] | Reset the scratch buffer to empty. The behavior is undefined unless `enable` has been previously called successfully (after the latest call to `disable` if `disable` has been called successfully). | 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. If the redirector is not in a redirected state, this method is a no‐op. 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. 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. If `disable` fails to disable the redirection, it will end the program by calling `std::abort`. | xref:BloombergLP/bsls/OutputRedirector/enable.adoc[`enable`] | If the `Stream` specified at construction was `e_STDOUT_STREAM`, redirect `stdout` to a temporary file. If the `Stream` specified at construction was `e_STDERR_STREAM`, redirect `stderr` to a temporary file. 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. If `enable` fails to redirect either `stdout` or `stderr` it will end the program by calling `std::abort`. | xref:BloombergLP/bsls/OutputRedirector/getOutput.adoc[`getOutput`] | Return the address of the scratch buffer. | xref:BloombergLP/bsls/OutputRedirector/isOutputReady.adoc[`isOutputReady`] | Return `true` if the captured output has been loaded into the scratch buffer, and `false` otherwise. | xref:BloombergLP/bsls/OutputRedirector/isRedirecting.adoc[`isRedirecting`] | Return `true` if `stdout` or `stderr` has been successfully redirected, and `false` otherwise. | xref:BloombergLP/bsls/OutputRedirector/load.adoc[`load`] | Read captured output into the scratch buffer. Return `true` if all captured output was successfully loaded, and `false` otherwise. Note that captured output is allowed to have zero length. The behavior is undefined unless `enable` has been previously called successfully (after the latest call to `disable`, if `disable` has been called successfully). | 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. | xref:BloombergLP/bsls/OutputRedirector/outputSize.adoc[`outputSize`] | Return the number of bytes currently loaded into the scratch buffer. | 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. | xref:BloombergLP/bsls/OutputRedirector/redirectedStreamId.adoc[`redirectedStreamId`] | Return `OutputRedirector::e_STDOUT_STREAM` if this object is responsible for redirecting `stdout`, and `OutputRedirector::e_STDERR_STREAM` if this object is responsible for redirecting `stderr`. |=== == Static Data Members [cols="1,4"] |=== | Name| Description | xref:BloombergLP/bsls/OutputRedirector/k_OUTPUT_REDIRECTOR_BUFFER_SIZE.adoc[`k_OUTPUT_REDIRECTOR_BUFFER_SIZE`] | The size of the buffer used to store the captured values loaded in the `stdout` and `stderr` error streams. | xref:BloombergLP/bsls/OutputRedirector/k_PATH_BUFFER_SIZE.adoc[`k_PATH_BUFFER_SIZE`] | The size of the buffer used to hold a file name. |=== [.small]#Created with https://www.mrdocs.com[MrDocs]#