|
|
@@ -162,12 +162,20 @@ void PrintUnicode(const String& str, bool error)
|
|
|
{
|
|
|
#if !defined(ANDROID) && !defined(IOS)
|
|
|
#ifdef WIN32
|
|
|
- HANDLE stream = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
|
|
|
- if (stream == INVALID_HANDLE_VALUE)
|
|
|
- return;
|
|
|
- WString strW(str);
|
|
|
- DWORD charsWritten;
|
|
|
- WriteConsoleW(stream, strW.CString(), strW.Length(), &charsWritten, 0);
|
|
|
+ // If the output stream has been redirected, use fprintf instead of WriteConsoleW,
|
|
|
+ // though it means that proper Unicode output will not work
|
|
|
+ FILE* out = error ? stderr : stdout;
|
|
|
+ if (!_isatty(_fileno(out)))
|
|
|
+ fprintf(out, "%s", str.CString());
|
|
|
+ else
|
|
|
+ {
|
|
|
+ HANDLE stream = GetStdHandle(error ? STD_ERROR_HANDLE : STD_OUTPUT_HANDLE);
|
|
|
+ if (stream == INVALID_HANDLE_VALUE)
|
|
|
+ return;
|
|
|
+ WString strW(str);
|
|
|
+ DWORD charsWritten;
|
|
|
+ WriteConsoleW(stream, strW.CString(), strW.Length(), &charsWritten, 0);
|
|
|
+ }
|
|
|
#else
|
|
|
fprintf(error ? stderr : stdout, "%s", str.CString());
|
|
|
#endif
|