Skip to content

install.ps1's programs read a byte-order mark from their closed standard input under Windows PowerShell 5.1 with a UTF-8 console #1104

Closed

Description

@David-Noble-at-work

Under Windows PowerShell 5.1 with a UTF-8 console, every program install.ps1 runs (self install, writ repo set, writ repo list) reads a byte-order mark, EF BB BF, from the standard input #1044 closed for it, before the end of that input. Ruled 2026-10-20: "We do not store boms. Ever!"

Observed

Cause

.NET Framework 4.8 (Windows PowerShell 5.1) builds a redirected standard input's writer from Console.InputEncoding and turns AutoFlush on at Process.Start, which writes the encoding's preamble at once: closing the writer, or the stream under it, cannot keep it out (tried on danoble-wd11-3). Its ProcessStartInfo has no StandardInputEncoding; .NET 10 (PowerShell 7) has one, and writes no preamble.

Fix

Ruled 2026-10-20, offered this, an inherited standard input, or cmd /c ... < NUL: "Implement your solution." Invoke-NativeCommand sets [Console]::InputEncoding to UTF-8 without a preamble for the moment Process.Start runs, when it is UTF-8 with one, and restores the caller's in a finally. The code page is 65001 throughout: section 7's rule that a script never changes the console's code page holds. Tried on danoble-wd11-3 under both editions: the program reads nothing, and the console's input encoding is the caller's again afterwards.

The suite's stdin check sets the probing session's input encoding to UTF-8 with a preamble first, so it catches the mark whatever console a runner has.

Plan and design documents

Kind Document
Plan docs/plans/fix/1104-install-ps1-s-programs-read-a.md
Guide PowerShell style guide, § 7, Native programs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions