OutputRedirector
OutputRedirector
C++ class exposed to Python to capture sys.stdout / sys.stderr. More…
#include <OutputRedirector.hpp>
Public Functions
| Name | |
|---|---|
| OutputRedirector() =default | |
| void | write(std::string const & text) Called by Python’s print() / sys.stdout.write(). |
| void | flush() Called by Python after print() — we buffer, so this is a no-op. |
| std::string | drain() Return and clear the accumulated text. |
| bool | readable() Python “file-like” protocol helpers. |
| bool | writable() |
| bool | seekable() |
Detailed Description
class OutputRedirector;C++ class exposed to Python to capture sys.stdout / sys.stderr.
An instance is injected as sys.stdout and sys.stderr inside the embedded interpreter. Every [write()](/api_generated/Classes/classOutputRedirector.md#function-write) call appends to an internal buffer that can be drained by C++ after execution completes.
The class satisfies the minimal Python “file-like object” protocol (write, flush, readable, writable, seekable) so that the Python runtime and libraries like traceback accept it without complaint.
Public Functions Documentation
function OutputRedirector
OutputRedirector() =defaultfunction write
inline void write(
std::string const & text
)Called by Python’s print() / sys.stdout.write().
function flush
inline void flush()Called by Python after print() — we buffer, so this is a no-op.
function drain
inline std::string drain()Return and clear the accumulated text.
function readable
static inline bool readable()Python “file-like” protocol helpers.
function writable
static inline bool writable()function seekable
static inline bool seekable()Updated on 2026-11-13 at 20:25:40 +0000