Skip to content

The -NoNewLine switch parameter of Out-File and Out-String should not strip embedded newlines from formatter-generated output  #5107

@mklement0

Description

@mklement0

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.txt

Note how the first input object uses the PS formatting system, whereas the second one doesn't.

Actual behavior:

one---  1two
three    # no trailing newline

Note 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 newline

You 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-Won't FixThe issue won't be fixed, possibly due to compatibility reason.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions