| 26 | #include <iostream> |
| 27 | |
| 28 | void RedirectHandle(DWORD handle, FILE* stream, const char* mode) |
| 29 | { |
| 30 | HANDLE stdHandle = GetStdHandle(handle); |
| 31 | if (stdHandle != INVALID_HANDLE_VALUE) { |
| 32 | int fileDescriptor = _open_osfhandle((intptr_t)stdHandle, _O_TEXT); |
| 33 | if (fileDescriptor != -1) { |
| 34 | FILE* file = _fdopen(fileDescriptor, mode); |
| 35 | if (file != NULL) { |
| 36 | int dup2Result = _dup2(_fileno(file), _fileno(stream)); |
| 37 | if (dup2Result == 0) { |
| 38 | setvbuf(stream, NULL, _IONBF, 0); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | // taken from https://stackoverflow.com/a/25927081 |
| 46 | // getting a proper output to console with redirection support on windows is apparently hell |
no outgoing calls
no test coverage detected