简体   繁体   English

使用 cmd 和 utf8 参数调用 Powershell

[英]Invoke Powershell with cmd and utf8 parameter

In a UTF-8 batch, I try to invoke:在 UTF-8 批处理中,我尝试调用:

powershell Start-Process cmd.exe -Verb runAs -Arg '/k chcp 65001 ^& echo été'

But the echo was :但回声是:

Page de codes active : 65001
├®t├®

C:\WINDOWS\system32>

I would like "été" and not "├®t├®"我想要“été”而不是“├®t├®”

You need to set the Console.OutputEncoding to UTF8 like this:您需要像这样将Console.OutputEncoding设置为 UTF8:

powershell.exe -Command {
    [Console]::OutputEncoding = [System.Text.Encoding]::Utf8
    Start-Process cmd.exe -Verb runAs -Arg '/k echo été'
}

Result:结果:

été été

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM