I have a perl script that produces utf8 output. I tried using Set-Content to write a utf8 file as suggested by Powershell overruling Perl binmode?.
perl -S testbinmode.pl | Set-Content "binmode.txt" -Encoding Byte
produces the error
"Set-Content : Cannot proceed with byte encoding. When using byte encoding the content must be of type byte."
perl -S testbinmode.pl | Set-Content "binmode.txt" -Encoding UTF8
doesn't produce an error message, but it doesn't write a correct utf8 file either.
The output of the perl script is displayed correctly in the Powershell window. What is the correct way to write that output to a utf8-encoded file?
Update: I have seen many responses to this and similar problems, here at the link referenced above, and at https://stackoverflow.com/questions/40098771/changing-powershells-default-output-encoding-to-utf-8. None of them appear to work, leading me to believe that not one has actually been tested. A tested method for redirecting UTF8 text output from a CLI program to a file is desired. Thanks.
Here is the perl test script:
use strict; use warnings; use utf8; binmode(STDOUT, ":utf8"); print("The Crüxshadows");