简体   繁体   中英

Invoke Powershell with cmd and utf8 parameter

In a UTF-8 batch, I try to invoke:

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├®"

You need to set the Console.OutputEncoding to UTF8 like this:

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

Result:

été

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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