[Base] Fix AttachConsole so that --help works when invoked from command-line.

This commit is contained in:
gibbed 2018-05-31 16:46:03 -05:00
parent d0df71b8b6
commit ceece673e8
1 changed files with 5 additions and 9 deletions

View File

@ -44,16 +44,12 @@ void AttachConsole() {
} }
has_console_attached_ = true; has_console_attached_ = true;
auto std_handle = (intptr_t)GetStdHandle(STD_OUTPUT_HANDLE); FILE* dummy;
auto con_handle = _open_osfhandle(std_handle, _O_TEXT); freopen_s(&dummy, "CONIN$", "rb", stdin);
auto fp = _fdopen(con_handle, "w"); freopen_s(&dummy, "CONOUT$", "wb", stdout);
*stdout = *fp; freopen_s(&dummy, "CONOUT$", "wb", stderr);
setvbuf(stdout, nullptr, _IONBF, 0);
std_handle = (intptr_t)GetStdHandle(STD_ERROR_HANDLE); setvbuf(stdout, nullptr, _IONBF, 0);
con_handle = _open_osfhandle(std_handle, _O_TEXT);
fp = _fdopen(con_handle, "w");
*stderr = *fp;
setvbuf(stderr, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0);
} }