On Tuesday, 18 July 2023 at 22:09:40 UTC, Adam D Ruppe wrote:
On Tuesday, 18 July 2023 at 21:31:54 UTC, Alexander Zhirov
wrote:
HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
WriteConsoleW(h_stderr, str.ptr, cast(DWORD)str.length,
NULL, NULL);
If you checked the return value of this call, you'd find it
fails since WriteConsole only works if the output is, in fact,
a console.
You need to use WriteFile when it is redirected, which you can
detect with GetFileType to see if it is a character device or
not.
Just found
[this](https://stackoverflow.com/questions/45805785/why-cant-i-redirect-output-from-writeconsole) on the net. Hmm... I didn't know that Windows has its own nuances in working with threads. Thanks for the tip.