Class to capture stdout and stderr.
More...
|
static int | ReadIntercept (unsigned long pFile, unsigned char *pBuff, uintptr_t *pCount, void *pThat) |
| Intercept input from FILE streams.
|
|
static int | WriteIntercept (unsigned long pFile, unsigned char *pBuff, uintptr_t *pCount, void *pThat) |
| Intercept output from FILE streams.
|
|
static int | SeekIntercept (unsigned long pFile, unsigned long *pPosition, int mode, void *pThat) |
| Intercept seek from FILE streams.
|
|
Class to capture stdout and stderr.
For quick redirection of the stdout and stderr output stream, create an instance of this class, and when capturing is needed create code like the example below.
void foo()
{
printf("Hello World!");
}
}
Class to capture stdout and stderr.
Definition burger.h:17509
eError Init(uintptr_t uBufferSize=65536U) noexcept
Intercept stdout and stderr.
Definition brcapturestdout.cpp:133
eError GetCapture(String *pOutput) noexcept
Store the contents of the pipe into a string.
Definition brcapturestdout.cpp:330
eError Shutdown(void) noexcept
Restore stdout and stderr.
Definition brcapturestdout.cpp:258
UTF 8 bit string class.
Definition burger.h:14855
@ kErrorNone
No error (Always zero).
Definition burger.h:4898
- Note
- This class affects stdout and stderr globally. Use this class with caution.
- See also
- Burger::OutputMemoryStream
◆ CaptureStdout() [1/3]
◆ CaptureStdout() [2/3]
◆ CaptureStdout() [3/3]
Burger::CaptureStdout::CaptureStdout |
( |
| ) |
|
|
noexcept |
◆ ~CaptureStdout()
Burger::CaptureStdout::~CaptureStdout |
( |
| ) |
|
◆ GetCapture()
Store the contents of the pipe into a string.
Flush the pipe and store the contents of the pipe into a passed String class instance. After this call, the interception pipe is reset so it can be refilled with intercepted output.
- Parameters
-
pOutput | Pointer to a String to store the data |
- Returns
- Error code
- See also
- Init(uintptr_t) or Shutdown(void)
◆ Init()
Intercept stdout and stderr.
Create a pipe with a specific byte length and redirect stdout and stderr into the new pipe.
- Parameters
-
uBufferSize | Number of bytes to allocate for the pipe's buffer |
- Returns
- Error code
- See also
- Shutdown(void) or GetCapture(String *)
◆ operator=() [1/2]
◆ operator=() [2/2]
◆ ReadIntercept()
int BURGER_ANSIAPI Burger::CaptureStdout::ReadIntercept |
( |
unsigned long | pFile, |
|
|
unsigned char * | pBuff, |
|
|
uintptr_t * | pCount, |
|
|
void * | pThat ) |
|
staticprivate |
Intercept input from FILE streams.
Return error
- Parameters
-
pFile | Not used. |
pBuff | Not used. |
pCount | Not used. |
pThat | Not used. |
- Returns
- EOF error.
- Note
- Only available with the Metrowerks compiler.
◆ SeekIntercept()
int BURGER_ANSIAPI Burger::CaptureStdout::SeekIntercept |
( |
unsigned long | pFile, |
|
|
unsigned long * | pPosition, |
|
|
int | mode, |
|
|
void * | pThat ) |
|
staticprivate |
Intercept seek from FILE streams.
Return error
- Parameters
-
pFile | Not used. |
pPosition | Not used. |
mode | Not used. |
pThat | Not used. |
- Returns
- I/O error.
- Note
- Only available with the Metrowerks compiler.
◆ Shutdown()
◆ WriteIntercept()
int BURGER_ANSIAPI Burger::CaptureStdout::WriteIntercept |
( |
unsigned long | pFile, |
|
|
unsigned char * | pBuff, |
|
|
uintptr_t * | pCount, |
|
|
void * | pThat ) |
|
staticprivate |
Intercept output from FILE streams.
The Metrowerks Standard Library uses a hard coded array of FILE records for stdin, stdout, stderr and null (In that order). Due to this, pipe is not supported, and hocus pocus is required to handle stream interception. This function replaces the write_proc callback to capture the text output.
- Parameters
-
pFile | Index into the __files array, 1 = stdout, 2 = stderr. |
pBuff | Bytes to transfer. |
pCount | Pointer to a count of bytes to transfer. |
pThat | Pointer to the Burger::CaptureStdout instance. |
- Returns
- Error code or zero if no error.
- Note
- Only available with the Metrowerks compiler.
◆ m_bActive
uint_t Burger::CaptureStdout::m_bActive |
|
private |
TRUE if currently capturing stream output
◆ m_iInputPipe
int Burger::CaptureStdout::m_iInputPipe |
|
private |
◆ m_iOutputPipe
int Burger::CaptureStdout::m_iOutputPipe |
|
private |
◆ m_iPreviousStderr
int Burger::CaptureStdout::m_iPreviousStderr |
|
private |
◆ m_iPreviousStdout
int Burger::CaptureStdout::m_iPreviousStdout |
|
private |
◆ m_pSaved
void* Burger::CaptureStdout::m_pSaved[2 *4] |
|
private |
Saved function pointers from stdout, stderr.
◆ m_Stream
Memory stream for capturing output.
◆ m_uCaptureSize
uintptr_t Burger::CaptureStdout::m_uCaptureSize |
|
private |
Maximum size of the capture pipe.