How do I output text without a newline in PowerShell?

前端 未结 17 2290
独厮守ぢ
独厮守ぢ 2020-12-07 15:13

I want my PowerShell script to print something like this:

Enabling feature XYZ......Done

The script looks something like this:



        
17条回答
  •  抹茶落季
    2020-12-07 15:53

    There seems to be no way to do this in PowerShell. All of the previous answers are not correct, because they do not behave the way Write-Output behaves but more like Write-Host which doesn't have this problem anyway.

    The closes solution seems to use Write-Host with the -NoNewLine parameter. You can not pipe this which is a problem generally, but there is a way to override this function as described in Write-Host => Export to a file, so you can easily make it accept the parameter for an output file. This is still far from a good solution. With Start-Transcript this is more usable, but that cmdlet has problems with native applications.

    Write-Outputsimply can't do what you need in a general context.

提交回复
热议问题