The main question I have is how can I get a textfile that I have in Linux to display properly in PowerShell.
In Linux, I have text files with some special characters, and in fact Notepad displays the text file exactly as it is displayed in Linux:
Unfortunately, my program prints to my Linux Terminal, and thus I need the same output in my Windows terminal. I have seen through other answers that
- I need to use a TrueType font, so I am using Lucidia Console
- on my Linux device, the encoding is UTF-8. According to every answer I can find online, CHCP 65001 switches the code page in PowerShell to UTF-8
- Windows Powershell is better equipped to display content, so while I have tried using the command prompt, I am now working in PowerShell.
Using CHCP 65001 and then typing
more my_file.txt
displays this:
while using
Get-Content -Encoding UTF8 my_file.txt
outputs:
Neither of these results is good enough, but I am actually concerned that Get-Content does something different at all here. The code that I am transferring to windows is written in Free Pascal, and in Free Pascal, I can provide a UTF-8 codepage, but that's it. So while Get-Content is a good command for me to check if PowerShell is capable of producing the desired output, it is not practical for me to use it. In Pascal, the output (which is written to the PowerShell display) appears as:
Which is bad as well, those lines should connect because they do in Linux (and obviously some characters are interpreted just as ?). However, this might be a problem with the codepage picked in Pascal, which would be a next step.
My question right now is, how can I get the Windows Powershell to, by default, display a text file as it is shown in the notepad version. It is not practical for me to run Get-Content in my code everywhere, so although that result appears more promising, I cannot follow that.
As a follow up question, because I could not find it anywhere online, what are the main players here when it comes to displaying content, because it is clearly a bigger story than just the encoding. Why are the 'more' and the 'Get-Content' commands displaying different outputs? And why can 'Get-Content' not read all of the content? I had assumed UTF-8 was a universal standard, and programs who can read UTF-8 could at least actually read all of the characters, but they're all reading it differently.
The input, as text, is:
╭─────╮
│ │
╭─│───╮ │
│ │ │ │
│ │ ╭─│───╮
│ │ │ │ │ │
╭─│───│─╯ │ │
│ │ │ │ │ │
│ │ ╰─╯ │ │
│ │ │ │
│ ╰───────│─╯
│ │
╰─────────╯
In response to an answer posted below, I can see that
more my_file.txt
produces
when using
$OutputEncoding = [console]::InputEncoding = [console]::OutputEncoding =
New-Object System.Text.UTF8Encoding