相关疑难解决方法(0)

PowerShell Set-Content和Out-File - 有什么区别?

在PowerShell中,Out-File和之间的区别是Set-Content什么?还是Add-ContentOut-File -append

我发现如果我对同一个文件使用两者,文本完全是mojibaked.

(小问题:>是别名Out-File,对吧?)

powershell

74
推荐指数
3
解决办法
8万
查看次数

在 PowerShell 中附加文本文件

因此,我正在尝试编写一个快速脚本来帮助我儿子学习拼字比赛。我几乎一切正常,但我想跟踪他的结果,所以我尝试将输出写入文本文件。我只关心最近的结果,所以当他开始测试时我删除了现有的结果文件。

我正在为每个人的拼写列表做一个,在每个列表的末尾,我有:

write-host "Word $counter - You spelled $wordcorrectly!!" | Out-File $outputpath -Append
Run Code Online (Sandbox Code Playgroud)

或者

write-host "Word $counter - Sorry.  The correct spelling is $word." | Out-File $outputpath -Append
Run Code Online (Sandbox Code Playgroud)

最后,在浏览完所有列表后,我得到:

write-host "You answered $counter out of $WordCount correctly" | Out-File $outputpath -Append
Run Code Online (Sandbox Code Playgroud)

但是当我转到 $outputpath 文件时,它完全是空白的......猜猜我在这里犯了什么简单的错误?

powershell append output

3
推荐指数
1
解决办法
5184
查看次数

标签 统计

powershell ×2

append ×1

output ×1