Command Prompt "tree" shows Unicode in console but outputs to file in ASCII
The encoding that is generally used for the box-drawing characters is 850, but even that doesn't help on my Windows 8.1 system. I've only found one way around cmd
's poor handling of text encodings: using a program that does handle encoding well, namely, PowerShell.
It's the >
redirection that wrecks the characters, so we'll just suck up the tree
output and jam it in a file without simple cmd
redirection:
Invoke-Expression "tree" | Out-File "tree.txt"
Or, shorter:
iex "tree" > "tree.txt"
To create an instance of PowerShell that runs that command and then exits, use this in a command prompt or batch file:
powershell -command "iex \"tree\" > \"tree.txt\""
The resulting file can be viewed successfully in Notepad or by a normal type
.