diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 86efa0dc..16802d08 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -25,7 +25,7 @@ #define WIN32_LEAN_AND_MEAN #endif #include - +#include #ifdef __MINGW32__ #include #endif @@ -147,6 +147,13 @@ inline int fopen_s(FILE** fp, const filename_t& filename, const filename_t& mode #else *fp = _fsopen((filename.c_str()), mode.c_str(), _SH_DENYWR); #endif + //don't let the handle be inherited by the child process + if (*fp != nullptr) { + HANDLE hFile = (HANDLE)_get_osfhandle(_fileno(*fp)); + if (hFile) { + SetHandleInformation(hFile, HANDLE_FLAG_INHERIT, 0); + } + } return *fp == nullptr; #else *fp = fopen((filename.c_str()), mode.c_str());