Tee-Object
没有-NoNewline
像许多其他输出到文件 cmdlet 那样的开关(例如Out-File
, Set-Content
)。在幕后,Tee-Object
用于Out-File
写入文件,默认情况下添加尾随换行符。
由于我(当前)无法通过-NoNewline
switch through Tee-Object
,是否有另一种方法可以强制底层Out-File
不会添加尾随换行符?看看 的实现Out-File
,现在可能有办法,但也许有人知道一些技巧/黑客来实现它?
一些限制:
- 我想
Tee-Object
在管道中使用(或替代解决方案) - 我不想对由
Tee-Object
(或替代解决方案)生成的文件进行后处理,例如再次打开它们并删除(最后一个)换行符。
复制代码:
"Test" | Tee-Object file | Out-Null
在 Windows 上,生成的文件file
将包含 6 个字节,如以下 hexdump 所示:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ASCII
00000000 54 65 73 74 0D 0A Test..
不幸的是,其中包含 Windows 中的附加字节0D 0A
aka`r`n
或 CR&LF。