MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / attachToConsole

Function attachToConsole

app/src/Platform/AppPlatform.cpp:227–245  ·  view source on GitHub ↗

* @brief Attaches the application to the parent console and redirects stdout/stderr. */

Source from the content-addressed store, hash-verified

225 * @brief Attaches the application to the parent console and redirects stdout/stderr.
226 */
227static void attachToConsole()
228{
229 if (handleIsRedirected(STD_OUTPUT_HANDLE)) {
230 bindStreamToStdHandle(STD_OUTPUT_HANDLE, stdout);
231 bindStreamToStdHandle(STD_ERROR_HANDLE, stderr);
232 return;
233 }
234
235 if (AttachConsole(ATTACH_PARENT_PROCESS)) {
236 FILE* fp = nullptr;
237 (void)freopen_s(&fp, "CONOUT$", "w", stdout);
238 (void)freopen_s(&fp, "CONOUT$", "w", stderr);
239 // code-verify off -- raw stdio is the only path before Qt is up
240 printf("\n");
241 // code-verify on
242
243 std::atexit(redrawConsolePromptAtExit);
244 }
245}
246
247/**
248 * @brief Pins the process to a stable Windows AppUserModelID.

Callers 1

prepareEnvironmentFunction · 0.85

Calls 2

handleIsRedirectedFunction · 0.85
bindStreamToStdHandleFunction · 0.85

Tested by

no test coverage detected