【发布时间】:2021-06-03 07:01:37
【问题描述】:
sn-p
powershell { Write-Host "a"; Write-Host "b" } > test.txt; Write-Host "File contents:"; cat test.txt; rm test.txt
打印
a
b
File contents:
a
b
为什么文本文件中每个Write-Host调用后都有2个空白行?
更令人困惑的是当我们将所有流重定向到一个文件时的行为:
powershell { Write-Host "a"; Write-Host "b" } *> test.txt; Write-Host "File contents:"; cat test.txt; rm test.txt
打印
File contents:
a
b
a
b
现在该文件包含两次所有内容,首先是 2 个空行,然后是正常的。为什么文件现在包含所有内容两次?
【问题讨论】:
-
powershell " Write-Host 'a'; Write-Host 'b' "