Class to intercept stdout and stderr and either capture, discard or keep them unmodified depending on the template arguments.
More...
#include <IOIntercept.h>
|
bool | start () |
| Start intercepting the output.
|
|
bool | finish () |
| Finish intercepting the output.
|
|
const std::string & | getStdOut () const |
| Return the captured stdout output if any.
|
|
const std::string & | getStdErr () const |
| Return the captured stderr output if any.
|
|
template<class STDOUT, class STDERR>
class Belle2::IOIntercept::InterceptOutput< STDOUT, STDERR >
Class to intercept stdout and stderr and either capture, discard or keep them unmodified depending on the template arguments.
For example
std::cout <<
"Output was: " << capture.
getStdOut() << std::endl;
Class to intercept stdout and stderr and either capture, discard or keep them unmodified depending on...
const std::string & getStdOut() const
Return the captured stdout output if any.
bool start()
Start intercepting the output.
bool finish()
Finish intercepting the output.
Shorthand classes are defined for all use cases, so in the above example we could have just used IOIntercept::CaptureStdOutDiscardStdErr;
- Warning
- the default capacity for capturing output is 64 kB but might be shorter on certain systems. If there is more output than this to either stdout or stderr while capturing it the captured output will be truncated and processes who check if output was successful might fail.
- See also
- CaptureStdOutStdErr, CaptureStdOut, CaptureStdErr, DiscardStdOutStdErr, DiscardStdOut, DiscardStdErr, CaptureStdOutDiscardStdErr, DiscardStdOutCaptureStdErr
Definition at line 151 of file IOIntercept.h.
◆ finish()
template<class STDOUT, class STDERR>
Finish intercepting the output.
This function can be called multiple times.
- Returns
- true if interception was active and could be removed successfully
Definition at line 158 of file IOIntercept.h.
158{ return m_stdout.finish() && m_stderr.finish(); }
◆ getStdErr()
template<class STDOUT, class STDERR>
const std::string & getStdErr |
( |
| ) |
const |
|
inline |
Return the captured stderr output if any.
Only filled after finish() is called
Definition at line 166 of file IOIntercept.h.
167 {
168 static_assert(std::is_same<STDERR, CaptureStream>::value, "Only valid if stderr is captured using CaptureStream");
169 return m_stderr.getOutput();
170 }
◆ getStdOut()
template<class STDOUT, class STDERR>
const std::string & getStdOut |
( |
| ) |
const |
|
inline |
Return the captured stdout output if any.
Only filled after finish() is called
Definition at line 160 of file IOIntercept.h.
161 {
162 static_assert(std::is_same<STDOUT, CaptureStream>::value, "Only valid if stdout is captured using CaptureStream");
163 return m_stdout.getOutput();
164 }
◆ start()
template<class STDOUT, class STDERR>
Start intercepting the output.
This function can be called multiple times.
- Returns
- true if interception could be started successfully or is already active
Definition at line 155 of file IOIntercept.h.
155{ return m_stdout.start() && m_stderr.start(); }
◆ m_stderr
template<class STDOUT, class STDERR>
STDERR m_stderr {std::cerr, stderr} |
|
private |
◆ m_stdout
template<class STDOUT, class STDERR>
STDOUT m_stdout {std::cout, stdout} |
|
private |
The documentation for this class was generated from the following file: