UTF-8 output from PowerShell

后端 未结 4 1790
我在风中等你
我在风中等你 2020-11-28 23:12

I\'m trying to use Process.Start with redirected I/O to call PowerShell.exe with a string, and to get the output back, all in UTF-8. But I don\'t s

4条回答
  •  囚心锁ツ
    2020-11-28 23:58

    Not an expert on encoding, but after reading these...

    • http://blogs.msdn.com/b/powershell/archive/2006/12/11/outputencoding-to-the-rescue.aspx
    • http://technet.microsoft.com/en-us/library/hh847796.aspx
    • http://www.johndcook.com/blog/2008/08/25/powershell-output-redirection-unicode-or-ascii/

    ... it seems fairly clear that the $OutputEncoding variable only affects data piped to native applications.

    If sending to a file from withing PowerShell, the encoding can be controlled by the -encoding parameter on the out-file cmdlet e.g.

    write-output "hello" | out-file "enctest.txt" -encoding utf8
    

    Nothing else you can do on the PowerShell front then, but the following post may well help you:.

    • http://blogs.msdn.com/b/ddietric/archive/2010/11/08/decoding-standard-output-and-standard-error-when-redirecting-to-a-gui-application.aspx

提交回复
热议问题