From 34d99cb07df7519c273aa352185df3a7e4a01bb9 Mon Sep 17 00:00:00 2001 From: Roman Lavrov Date: Wed, 25 Mar 2026 16:24:21 -0400 Subject: Skip SetConsoleCP when stdout is non-interactive. Fixes wixtoolset/issues#9267 --- src/libs/dutil/WixToolset.DUtil/conutil.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/libs/dutil') diff --git a/src/libs/dutil/WixToolset.DUtil/conutil.cpp b/src/libs/dutil/WixToolset.DUtil/conutil.cpp index 059af0e0..858128cd 100644 --- a/src/libs/dutil/WixToolset.DUtil/conutil.cpp +++ b/src/libs/dutil/WixToolset.DUtil/conutil.cpp @@ -67,9 +67,14 @@ extern "C" HRESULT DAPI ConsoleInitialize() vfConsoleOut = TRUE; } - if (!::SetConsoleCP(CP_UTF8) || !::SetConsoleOutputCP(CP_UTF8)) + // Console codepage only applies to interactive sessions. SetConsoleCP may + // fail in console-less environments and the error path closes stdin/stdout. + if (vfStdOutInteractive) { - ConExitWithLastError(hr, "failed to set console codepage to UTF-8"); + if (!::SetConsoleCP(CP_UTF8) || !::SetConsoleOutputCP(CP_UTF8)) + { + ConExitWithLastError(hr, "failed to set console codepage to UTF-8"); + } } LExit: -- cgit v1.2.3-55-g6feb