MCPcopy Create free account
hub / github.com/OpenMW/openmw / attachParentConsole

Function attachParentConsole

components/debug/debugging.cpp:55–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53 }
54
55 bool attachParentConsole()
56 {
57 if (GetConsoleWindow() != nullptr)
58 return true;
59
60 bool inRedirected = isRedirected(STD_INPUT_HANDLE);
61 bool outRedirected = isRedirected(STD_OUTPUT_HANDLE);
62 bool errRedirected = isRedirected(STD_ERROR_HANDLE);
63
64 // Note: Do not spend three days reinvestigating this PowerShell bug thinking its our bug.
65 // https://gitlab.com/OpenMW/openmw/-/merge_requests/408#note_447467393
66 // The handles look valid, but GetFinalPathNameByHandleA can't tell what files they go to and writing to them
67 // doesn't work.
68
69 if (AttachConsole(ATTACH_PARENT_PROCESS))
70 {
71 fflush(stdout);
72 fflush(stderr);
73 std::cout.flush();
74 std::cerr.flush();
75
76 // this looks dubious but is really the right way
77 if (!inRedirected)
78 {
79 _wfreopen(L"CON", L"r", stdin);
80 freopen("CON", "r", stdin);
81 std::cin.clear();
82 }
83 if (!outRedirected)
84 {
85 _wfreopen(L"CON", L"w", stdout);
86 freopen("CON", "w", stdout);
87 std::cout.clear();
88 }
89 if (!errRedirected)
90 {
91 _wfreopen(L"CON", L"w", stderr);
92 freopen("CON", "w", stderr);
93 std::cerr.clear();
94 }
95
96 return true;
97 }
98
99 return false;
100 }
101#endif
102
103 static LogListener logListener;

Callers 1

wrapApplicationFunction · 0.85

Calls 3

isRedirectedFunction · 0.85
flushMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected