Prevent trailing newline in PowerShell Out-File command

后端 未结 3 674
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 17:20

How do I prevent PowerShell\'s Out-File command from appending a newline after the text it outputs?

For example, running the following command produces a file with c

3条回答
  •  别那么骄傲
    2020-12-15 17:47

    In PowerShell 5.0+, you would use:

    "TestTest" | Out-File -encoding ascii test.txt -NoNewline
    

    But in earlier versions you simply can't with that cmdlet.

    Try this:

    [System.IO.File]::WriteAllText($FilePath,"TestTest",[System.Text.Encoding]::ASCII)
    

提交回复
热议问题