Skip to content

Add -NonInteractive to the Windows PowerShell launch - #3

Open
dbwiddis wants to merge 1 commit into
pandalxb:mainfrom
dbwiddis:noninteractive
Open

Add -NonInteractive to the Windows PowerShell launch#3
dbwiddis wants to merge 1 commit into
pandalxb:mainfrom
dbwiddis:noninteractive

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Sep 2, 2026

Copy link
Copy Markdown

Resolves #2.

One line: adds -NonInteractive to the Windows powershell.exe argument list in
PowerShell.initalize.

Why

-Command - makes the console host run its interactive input loop, which loads PSReadLine. On a host
where the console handle is not a real screen buffer — a CI build agent, for example —
PSConsoleReadLine.Initialize throws The handle is invalid while reading the buffer width, catches
it, and prints a bug-report banner. Because initalize also calls redirectErrorStream(true), that
banner lands in the same stream the caller parses, corrupting the result of whatever command was
running.

-NonInteractive fixes it at the cause: PSReadLine is never loaded, so the banner cannot be emitted.
Commands are still read from stdin and results are still returned normally.

Verification

Measured on the Windows Server 2019 image where this reproduces, launching PowerShell exactly as this
library does, three iterations each:

Argument list Banner Get-Module PSReadLine in the session
as shipped 3 of 3 2.0.0 — loaded
with -NonInteractive 0 of 3 empty — not loaded

Also confirmed clean on Windows Server 2022 (build 20348) and 2025 (build 26100), which do not
reproduce the bug in the first place, so the change does not regress hosts that were already working.

Full public build log: https://ci.appveyor.com/project/dbwiddis/oshi/builds/54645282

Scope

Deliberately limited to the Windows branch, where the problem is reproduced and the fix is measured.
I have not touched the non-Windows ProcessBuilder or redirectErrorStream(true); changing the
latter would alter behaviour for every consumer and is discussed in #2 instead.

Without it, -Command - puts the console host into its interactive input
loop, which loads PSReadLine. On hosts where the console handle is not a
real screen buffer, PSConsoleReadLine.Initialize throws while reading the
buffer width and prints a bug-report banner, which redirectErrorStream(true)
merges into the stream the caller parses.

With -NonInteractive, PSReadLine is never loaded, so the banner cannot be
emitted. Commands are still read from stdin and results returned normally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSReadLine banner is merged into command output on Windows Server 2019 build agents, corrupting parsed results

1 participant