Skip to content

out-file -append (or ">>") can mix two encodings in the same file #9423

@jszabo98

Description

@jszabo98

Out-file -append (or ">>") can mix two encodings, like unicode and utf8, in the same file. Add-content doesn't seem to suffer from this. Note that out-file in PS 5.1 uniquely defaults to unicode
(undocumented). But the problem itself is in both out-file for PS 5.1 & PS 6.

Steps to reproduce

PS /Users/js> write-output hi | set-content hi.txt -Encoding unicode
PS /Users/js> write-output hi | out-file -Append hi.txt
PS /Users/js> get-content hi.txt

(or write-output hi >> hi.txt for line 2)

Expected behavior

hi
hi

Actual behavior

line one is unicode, line 2 is utf8

hi
楨

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.0
PSEdition                      Core
GitCommitId                    6.2.0
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 21 20:07:39 PDT 2018; root:xnu-3789.73.14~1/RELEASE_X86_64
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or moreUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-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