|
14 | 14 | #include <errhandlingapi.h>
|
15 | 15 | #include <fcntl.h>
|
16 | 16 | #include <IntSafe.h>
|
17 |
| -#include <ProcessEnv.h> |
18 | 17 | #include <wincon.h>
|
19 | 18 |
|
20 | 19 | #elif (BOOST_OS_MACOS)
|
@@ -113,25 +112,57 @@ int Platform::defaultBackEnd() {
|
113 | 112 | }
|
114 | 113 |
|
115 | 114 | #if (BOOST_OS_WINDOWS)
|
| 115 | +// std::ofstream Platform::conOutStream; |
| 116 | +std::unique_ptr<FILE, decltype(&fclose)> Platform::stdErrStream{nullptr, fclose}; |
| 117 | +// std::unique_ptr<FILE, decltype(&fclose)> Platform::stdOutFd{nullptr, fclose}; |
| 118 | +// std::unique_ptr<FILE, decltype(&fclose)> Platform::oldStdOutFd{nullptr, fclose}; |
116 | 119 | int Platform::stderr_fd;
|
| 120 | +// int Platform::stdout_file; |
| 121 | + |
| 122 | +std::unique_ptr<HANDLE, decltype(&CloseHandle)> Platform::stdOutHandle{nullptr, CloseHandle}; |
117 | 123 |
|
118 | 124 | void Platform::initWindowsConsole() {
|
119 | 125 | if (AttachConsole(ATTACH_PARENT_PROCESS) == 0 || fileno(stdout) == -2 || fileno(stderr) == -2) {
|
120 | 126 | auto ptr = stdErrStream.get();
|
121 | 127 | freopen_s(&ptr, "NUL", "w", stderr);
|
122 | 128 | }
|
123 | 129 | else {
|
124 |
| - freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); |
125 | 130 | freopen_s((FILE**)stderr, "CONOUT$", "w", stderr);
|
126 |
| - std::ios::sync_with_stdio(true); |
| 131 | + freopen_s((FILE**)stdout, "CONOUT$", "w", stdout); |
| 132 | + HANDLE hStdout = CreateFile( |
| 133 | + "CONOUT$", GENERIC_READ | GENERIC_WRITE, |
| 134 | + FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, |
| 135 | + OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL |
| 136 | + ); |
| 137 | + stdOutHandle.reset(&hStdout); |
| 138 | + SetStdHandle(STD_OUTPUT_HANDLE, *stdOutHandle); |
| 139 | +// int conOutHandle = _open_osfhandle((intptr_t) GetStdHandle(STD_OUTPUT_HANDLE), _O_TEXT); |
| 140 | +// if (conOutHandle != -1) { |
| 141 | +// stdOutFd.reset(_fdopen(conOutHandle, "w")); |
| 142 | +// if (stdOutFd) { |
| 143 | +// oldStdOutFd.reset(stdout); |
| 144 | +// *stdout = *stdOutFd; |
| 145 | +// } |
| 146 | +// } |
| 147 | +// else { |
| 148 | +// fmt::print("Error in call to _open_osfhandle."); |
| 149 | +// } |
127 | 150 | std::setvbuf(stdout, nullptr, _IONBF, 0);
|
128 |
| - std::setvbuf(stderr, nullptr, _IONBF, 0); |
129 | 151 | std::cout.clear();
|
130 |
| - std::cerr.clear(); |
131 | 152 | std::wcout.clear();
|
132 |
| - std::wcerr.clear(); |
| 153 | + std::cout << "Testing cout, derp." << std::endl; |
| 154 | +// conOutStream = std::ofstream{"CONOUT$", std::ios::out}; |
| 155 | +// std::cout.rdbuf(conOutStream.rdbuf()); |
| 156 | +// std::setvbuf(stdout, nullptr, _IONBF, 0); |
| 157 | + |
| 158 | +// std::ios::sync_with_stdio(true); |
| 159 | +// std::setvbuf(stderr, nullptr, _IONBF, 0); |
| 160 | + |
| 161 | +// std::cerr.clear(); |
| 162 | +// std::wcerr.clear(); |
133 | 163 | }
|
134 | 164 | stderr_fd = fileno(stderr);
|
| 165 | +// stdout_file = fileno(stdout); |
135 | 166 | }
|
136 | 167 |
|
137 | 168 | extern "C" {
|
|
0 commit comments