PowerShell 管道会自动加换行符
数据经过管道 | 这么一传,就多了 \r\n 字符(在 Windows,平台相关)
$ (Write-Output "").Length
0
$ Write-Output "" | hexyl.exe --border none
00000000 0d 0a
$ @"
> uname
> uname
> "@ | wsl
Linux
-bash: 行 2: $'uname\r': 未找到命令- stdin - PowerShell’s pipe adds linefeed - Stack Overflow
- Piping Text To An External Program Appends A Trailing Newline · Issue #5974 · PowerShell/PowerShell
- linux - Piping Text To An External Program Appends A Trailing Newline - Stack Overflow
微软说这是By Design,那就随它去吧,肯定不愿改。
好在只是出现在 PowerShell 中,我可以用 Announcing Built-in Core Utilities for Windows | Task TaskFile 绕过这个限制。