Skip to content

Commit 2c4e609

Browse files
committed
Skip SetConsoleCP when stdout is non-interactive.
Fixes wixtoolset/issues#9267
1 parent b4da272 commit 2c4e609

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/libs/dutil/WixToolset.DUtil/conutil.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,14 @@ extern "C" HRESULT DAPI ConsoleInitialize()
6767
vfConsoleOut = TRUE;
6868
}
6969

70-
if (!::SetConsoleCP(CP_UTF8) || !::SetConsoleOutputCP(CP_UTF8))
70+
// Console codepage only applies to interactive sessions. SetConsoleCP may
71+
// fail in console-less environments and the error path closes stdin/stdout.
72+
if (vfStdOutInteractive)
7173
{
72-
ConExitWithLastError(hr, "failed to set console codepage to UTF-8");
74+
if (!::SetConsoleCP(CP_UTF8) || !::SetConsoleOutputCP(CP_UTF8))
75+
{
76+
ConExitWithLastError(hr, "failed to set console codepage to UTF-8");
77+
}
7378
}
7479

7580
LExit:

0 commit comments

Comments
 (0)