diff --git a/main/source/window/linux_window.cpp b/main/source/window/linux_window.cpp index 077a80d4f..492412086 100644 --- a/main/source/window/linux_window.cpp +++ b/main/source/window/linux_window.cpp @@ -10,6 +10,7 @@ #include #include + #include #include #include @@ -24,6 +25,11 @@ namespace hex { setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true); } + // Various libraries sadly directly print to stderr with no way to disable it + // We redirect stderr to /dev/null to prevent this + freopen("/dev/null", "w", stderr); + setvbuf(stderr, nullptr, _IONBF, 0); + // Redirect stdout to log file if we're not running in a terminal if (!isatty(STDOUT_FILENO)) { log::redirectToFile(); diff --git a/main/source/window/macos_window.cpp b/main/source/window/macos_window.cpp index c54fb4df7..63760e98b 100644 --- a/main/source/window/macos_window.cpp +++ b/main/source/window/macos_window.cpp @@ -10,6 +10,7 @@ #include #include + #include #include #include @@ -23,6 +24,11 @@ namespace hex { setenv("LD_LIBRARY_PATH", hex::format("{};{}", hex::getEnvironmentVariable("LD_LIBRARY_PATH").value_or(""), path.string().c_str()).c_str(), true); } + // Various libraries sadly directly print to stderr with no way to disable it + // We redirect stderr to /dev/null to prevent this + freopen("/dev/null", "w", stderr); + setvbuf(stderr, nullptr, _IONBF, 0); + // Redirect stdout to log file if we're not running in a terminal if (!isatty(STDOUT_FILENO)) { log::redirectToFile(); diff --git a/main/source/window/win_window.cpp b/main/source/window/win_window.cpp index 0a4ae40ad..1fab32bdc 100644 --- a/main/source/window/win_window.cpp +++ b/main/source/window/win_window.cpp @@ -24,6 +24,7 @@ #include #include + #include #include @@ -203,15 +204,18 @@ namespace hex { AddDllDirectory(path.c_str()); } + // Various libraries sadly directly print to stderr with no way to disable it + // We redirect stderr to NUL to prevent this + freopen("NUL:", "w", stderr); + setvbuf(stderr, nullptr, _IONBF, 0); + // Attach to parent console if one exists if (AttachConsole(ATTACH_PARENT_PROCESS)) { - // Redirect cin, cout and cerr to that console + // Redirect stdin and stdout to that new console freopen("CONIN$", "r", stdin); freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); setvbuf(stdin, nullptr, _IONBF, 0); setvbuf(stdout, nullptr, _IONBF, 0); - setvbuf(stderr, nullptr, _IONBF, 0); fmt::print("\n");