diff --git a/Source/script.cpp b/Source/script.cpp index 2a9a5149..d7c5e85c 100644 --- a/Source/script.cpp +++ b/Source/script.cpp @@ -3195,7 +3195,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) const TCHAR *cmdname=get_commandtoken_name(which_token); const TCHAR *exec=line.gettoken_str(1), *define=0; int comp=line.gettoken_enum(2,_T("<\0>\0<>\0=\0ignore\0")); - int validparams=true, ret=-1, cmpv=0; + int validparams=true, ret=-1, cmpv=0, forceutf8=0; switch(line.getnumtokens()-1) { case 1: comp=4; break; @@ -3211,11 +3211,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) TCHAR buf[33]; compile=_T("\""), compile+=get_executable_path(g_argv0), compile+= _T("\""); compile+= _T(" ") OPT_STR _T("v"), wsprintf(buf,_T("%d"),get_verbosity()), compile+=buf; -#ifdef _WIN32 // POSIX does not support -OUTPUTCHARSET - extern NStreamEncoding g_outputenc; - NStreamEncoding childenc=g_outputenc; - if (childenc.IsUnicode()) childenc.SetCodepage(NStreamEncoding::UTF8); // UTF-8 is the only Unicode encoding supported by RunChildProcessRedirected - compile+= _T(" ") OPT_STR _T("OCS "), childenc.GetCPDisplayName(buf), compile+=buf; +#if defined(_WIN32) && defined(_UNICODE) // POSIX does not support -OUTPUTCHARSET + compile+= _T(" ") OPT_STR _T("OCS UTF8"), forceutf8++; // Force UTF-8 and disable batch-file workaround in RunChildProcessRedirected #endif if (*exec) compile+= _T(" "), compile+=exec; exec=compile.c_str(); @@ -3224,7 +3221,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line) if (preprocessonly) PREPROCESSONLY_BEGINCOMMENT(); #ifdef _WIN32 if (TOK_P_SYSTEMEXEC != which_token) - ret=RunChildProcessRedirected(exec); + ret=RunChildProcessRedirected(exec, forceutf8 ? true : false); else #endif //~ _WIN32 ret=sane_system(exec); diff --git a/Source/util.cpp b/Source/util.cpp index 85c85137..43e6ac19 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -848,7 +848,7 @@ const TCHAR* GetFriendlySize(UINT64 n, unsigned int&fn, GETFRIENDLYSIZEFLAGS f) #ifdef _WIN32 #ifdef _UNICODE -int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain) +int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain, bool ForceUTF8) { // We have to deliver the requested output encoding to our host (if any) and the // only way to do that is to convert the pipe content from what we hope is UTF-8. @@ -865,7 +865,7 @@ int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain) SECURITY_DESCRIPTOR sd = { 1, 0, SE_DACL_PRESENT, NULL, }; SECURITY_ATTRIBUTES sa = { sizeof(sa), &sd, TRUE }; const UINT orgwinconcp = GetConsoleCP(), orgwinconoutcp = GetConsoleOutputCP(); - if (orgwinconoutcp == oemcp) cp = oemcp, mbtwcf = 0; // Bug #1092: Batch files not a fan of UTF-8 + if (orgwinconoutcp == oemcp && !ForceUTF8) cp = oemcp, mbtwcf = 0; // Bug #1092: Batch files not a fan of UTF-8 HANDLE hSIRd, hSIWr, hSORd, hSOWr; PROCESS_INFORMATION pi; if (!CreatePipe(&hSIRd, &hSIWr, &sa, 0)) // XCopy.exe does not work without a valid StdIn! @@ -961,7 +961,7 @@ switchcp: cp = orgwinconoutcp, mbtwcf = 0, utf8 = false; return childec; } #else -int RunChildProcessRedirected(LPCSTR cmd) +int RunChildProcessRedirected(LPCSTR cmd, bool ForceUTF8) { STARTUPINFO si = { sizeof(STARTUPINFO), }; PROCESS_INFORMATION pi; diff --git a/Source/util.h b/Source/util.h index ef24374c..ea148cec 100644 --- a/Source/util.h +++ b/Source/util.h @@ -109,8 +109,8 @@ void PrintColorFmtMsg(unsigned int type, const TCHAR *fmtstr, va_list args); void FlushOutputAndResetPrintColor(); #ifdef _WIN32 #ifdef _UNICODE -int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain); -inline int RunChildProcessRedirected(LPCWSTR cmd) { return RunChildProcessRedirected(0, cmd); } +int RunChildProcessRedirected(LPCWSTR cmdprefix, LPCWSTR cmdmain, bool ForceUTF8 = false); +inline int RunChildProcessRedirected(LPCWSTR cmd, bool ForceUTF8 = false) { return RunChildProcessRedirected(0, cmd, ForceUTF8); } #ifdef MAKENSIS typedef struct { HANDLE hNative; @@ -140,7 +140,7 @@ int WinStdIO_wprintf(const wchar_t*Fmt, ...); #define _vftprintf WinStdIO_vfwprintf #endif // ~MAKENSIS #else -int RunChildProcessRedirected(LPCSTR cmd); +int RunChildProcessRedirected(LPCSTR cmd, bool ForceUTF8 = false); #endif // ~_UNICODE #define ResetPrintColor() FlushOutputAndResetPrintColor() // For reset ONLY, use PrintColorFmtMsg(0,NULL ... #define SetPrintColorWARN() PrintColorFmtMsg(1|0x10, NULL, (va_list)NULL)