zom*_*ega 5 unicode powershell
我有一个 PowerShell 脚本。它执行生成 UTF-16 输出的 exe 文件,我将其通过管道传输到 Select-String 中,如下所示:
& "my.exe" | Select-String -Pattern "skipping non-regular file" -NotMatch -Encoding "utf-16"
Run Code Online (Sandbox Code Playgroud)
但 PowerShell 报告不支持该编码。
有解决方法来解决这个问题吗?UTF-16真的不支持吗?
这是我想出的一个例子。我不知道如何让它发挥作用。
程序.cs:
using System;
using System.Text;
namespace myApp
{
class Program
{
static void Main(string[] args)
{
Byte[] byteOrderMark;
byteOrderMark = Encoding.Unicode.GetPreamble();
//Console.OutputEncoding = new UnicodeEncoding(false, true);
Console.OutputEncoding = System.Text.Encoding.Unicode;
Console.WriteLine("Hello World!");
}
}
}
Run Code Online (Sandbox Code Playgroud)
$env:path += ';C:\Windows\Microsoft.NET\Framework64\v4.0.30319'
csc Program.cs
# no output for either
.\Program | select-string Hello
.\Program | select-string Hello -encoding unicode
# no 'FF FE' BOM
.\program | Format-Hex
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
00000000 48 00 65 00 6C 00 6C 00 6F 00 20 00 57 00 6F 00 H.e.l.l.o. .W.o.
00000010 72 00 6C 00 64 00 21 00 r.l.d.!.
Run Code Online (Sandbox Code Playgroud)
如果您想费心寻找每个字母之间的空值:
.\program | select-string h`0e
H e l l o W o r l d !
Run Code Online (Sandbox Code Playgroud)
在我看来,使用 utf8 仍然是最好的选择,即使 Windows 终端可用。
| 归档时间: |
|
| 查看次数: |
2560 次 |
| 最近记录: |