How do I pipe Unicode into a native application in PowerShell How do I pipe Unicode into a native application in PowerShell powershell powershell

How do I pipe Unicode into a native application in PowerShell


Thanks to mike z, the following works:

$OutputEncoding = [Console]::OutputEncoding = (new-object System.Text.UTF8Encoding $false)$env:PYTHONIOENCODING = "utf-8"python -c "print('\N{Euro sign}')" | python -c "import sys; print(sys.stdin.read())"

The new-object is needed to get a UTF-8 encoding without a BOM. The $OutputEncoding variable and [Console]::OutputEncoding both appear to need to be set.

I still don't fully understand the difference between the two encoding values, and why you would ever have them set differently (which appears to be the default).