Redirecting standard streams in Windows

Alexander Zhirov azhirov1991 at gmail.com
Tue Jul 18 21:31:54 UTC 2023


I'm trying to redirect unicode in the windows console, but when 
redirecting, empty files are created. If i do it without 
redirects, then the text is displayed correctly in the console:

```d
import core.sys.windows.windows;
import std.stdio;

void main() {
     wstring str = "Just text...";
     HANDLE h_stderr = GetStdHandle(STD_ERROR_HANDLE);
     HANDLE h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
     WriteConsoleW(h_stderr, str.ptr, cast(DWORD)str.length, NULL, 
NULL);
     WriteConsoleW(h_stdout, str.ptr, cast(DWORD)str.length, NULL, 
NULL);
}
```

```sh
.\app.exe 1> stdout.txt 2> stderr.txt
```


More information about the Digitalmars-d-learn mailing list