How do I output text without a newline in PowerShell?

前端 未结 17 2327
独厮守ぢ
独厮守ぢ 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:46

    The problem that I hit was that Write-Output actually linebreaks the output when using using PowerShell v2, at least to stdout. I was trying to write an XML text to stdout without success, because it would be hard wrapped at character 80.

    The workaround was to use

    [Console]::Out.Write($myVeryLongXMLTextBlobLine)
    

    This was not an issue in PowerShell v3. Write-Output seems to be working properly there.

    Depending on how the PowerShell script is invoked, you may need to use

    [Console]::BufferWidth =< length of string, e.g. 10000)
    

    before you write to stdout.

提交回复
热议问题