From 9845b0a889808116b28061675ef4e0f66c8e90d4 Mon Sep 17 00:00:00 2001 From: Jan Laupetin Date: Fri, 10 Oct 2025 10:18:43 +0100 Subject: [PATCH] chore: attach to console on windows if possible --- src/ModMan/main.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ModMan/main.cpp b/src/ModMan/main.cpp index a6afc7bb..66780792 100644 --- a/src/ModMan/main.cpp +++ b/src/ModMan/main.cpp @@ -5,13 +5,16 @@ #include "Web/ViteAssets.h" #include "Web/WebViewLib.h" -#include #include #include #include #include #include +#ifdef _WIN32 +#include +#endif + using namespace std::string_literals; using namespace PLATFORM_NAMESPACE; @@ -105,10 +108,23 @@ namespace #ifdef _WIN32 int WINAPI WinMain(HINSTANCE /*hInst*/, HINSTANCE /*hPrevInst*/, LPSTR /*lpCmdLine*/, int /*nCmdShow*/) -{ #else int main() +#endif { +#ifdef _WIN32 + // Attach console if possible on Windows for stdout/stderr in console + if (AttachConsole(-1)) + { + FILE* fDummy; + (void)freopen_s(&fDummy, "CONOUT$", "w", stdout); + (void)freopen_s(&fDummy, "CONOUT$", "w", stderr); + (void)freopen_s(&fDummy, "CONIN$", "r", stdin); + std::cout.clear(); + std::clog.clear(); + std::cerr.clear(); + std::cin.clear(); + } #endif con::info("Starting ModMan " GIT_VERSION);