Bind stdout and stderr for windows so that the console can get output

This commit is contained in:
Marek Roszko 2022-09-29 00:22:51 -04:00
parent 519084546e
commit 2b42163379
1 changed files with 20 additions and 0 deletions

View File

@ -61,6 +61,26 @@ bool KIPLATFORM::APP::Init()
// Moves the CWD to the end of the search list for spawning processes // Moves the CWD to the end of the search list for spawning processes
SetSearchPathMode( BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT ); SetSearchPathMode( BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT );
// In order to support GUI and CLI
// Let's attach to console when it's possible
HANDLE handleStdOut, handleStdErr;
if( AttachConsole( ATTACH_PARENT_PROCESS ) )
{
handleStdOut = GetStdHandle( STD_OUTPUT_HANDLE );
if( handleStdOut != INVALID_HANDLE_VALUE )
{
freopen( "CONOUT$", "w", stdout );
setvbuf( stdout, NULL, _IONBF, 0 );
}
handleStdErr = GetStdHandle( STD_ERROR_HANDLE );
if( handleStdErr != INVALID_HANDLE_VALUE )
{
freopen( "CONOUT$", "w", stderr );
setvbuf( stderr, NULL, _IONBF, 0 );
}
}
return true; return true;
} }