-
Notifications
You must be signed in to change notification settings - Fork 8.2k
The -NoNewLine switch parameter of Out-File and Out-String should not strip embedded newlines from formatter-generated output #5107
Description
Follow-up to #3684.
With multiple input objects, the -NoNewline switch causes said cmdlets not to place a newline after each (output representation of) the input object - in other words: the input objects' (representations) are directly concatenated.
While the usefulness of this behavior is debatable, it should work consistently with respect to how newlines embedded in input object representations are handled.
Currently,
-
formatter-generated output representations have their embedded newlines stripped
-
.ToString()generated output representations have their embedded newlines _preserved.
It is the latter behavior that should be consistently applied.
Steps to reproduce:
([pscustomobject] @{ one = 1 }), "two`nthree" | Out-File -NoNewline t.txt; Get-Content -raw t.txtNote how the first input object uses the PS formatting system, whereas the second one doesn't.
Actual behavior:
one--- 1two
three # no trailing newlineNote how the internal newlines were stripped from the default output formatting for @{ one = 1 }, which is:
one
---
1
Expected behavior:
one
---
1two
three # no trailing newlineYou could argue that -NoNewline with formatter-generated output doesn't make much sense with multiple input objects, and the mixing with .ToString() formatted objects produces strange effects, but stripping all embedded newlines makes even less sense.
Environment data
PowerShell Core v6.0.0-beta.8