Unicode redirection results in empty file #6782

Closed
opened 2026-01-31 00:47:08 +00:00 by claunia · 1 comment
Owner

Originally created by @AnFunctionArray on GitHub (Mar 8, 2020).

Platform ServicePack Version VersionString


Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0

Windows Terminal (Preview)
Version: 0.9.433.0

Consider the following example C program (use MSVC to compile):

main() {
AllocConsole();
WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\x1F600\x1F600\x1F600", 3, NULL, NULL);
}

Run:

./program | Out-File -Encoding Unicode -LiteralPath ./out.txt

I expect to get an UTF-16 encoded text file I can somehow open with WordPad or maybe a web browser and get three smiles.

An empty file.

Originally created by @AnFunctionArray on GitHub (Mar 8, 2020). Platform ServicePack Version VersionString -------- ----------- ------- ------------- Win32NT 10.0.18363.0 Microsoft Windows NT 10.0.18363.0 Windows Terminal (Preview) Version: 0.9.433.0 Consider the following example C program (use MSVC to compile): ``` main() { AllocConsole(); WriteConsoleW(GetStdHandle(STD_OUTPUT_HANDLE), L"\x1F600\x1F600\x1F600", 3, NULL, NULL); } ``` Run: `./program | Out-File -Encoding Unicode -LiteralPath ./out.txt` I expect to get an UTF-16 encoded text file I can somehow open with WordPad or maybe a web browser and get three smiles. An empty file.
claunia added the Resolution-By-DesignNeeds-Tag-Fix labels 2026-01-31 00:47:08 +00:00
Author
Owner

@DHowett-MSFT commented on GitHub (Mar 8, 2020):

You are explicitly calling WriteConsole, which is an API that only works if your output handle is a console. Since you’ve redirected it to either a file or a pipe, it’s not a console.

@DHowett-MSFT commented on GitHub (Mar 8, 2020): You are explicitly calling _WriteConsole_, which is an API that only works if your output handle is a console. Since you’ve redirected it to either a file or a pipe, it’s not a console.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#6782