Add -NonInteractive to the Windows PowerShell launch - #3
Open
dbwiddis wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #2.
One line: adds
-NonInteractiveto the Windowspowershell.exeargument list inPowerShell.initalize.Why
-Command -makes the console host run its interactive input loop, which loads PSReadLine. On a hostwhere the console handle is not a real screen buffer — a CI build agent, for example —
PSConsoleReadLine.InitializethrowsThe handle is invalidwhile reading the buffer width, catchesit, and prints a bug-report banner. Because
initalizealso callsredirectErrorStream(true), thatbanner lands in the same stream the caller parses, corrupting the result of whatever command was
running.
-NonInteractivefixes 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:
Get-Module PSReadLinein the session2.0.0— loaded-NonInteractiveAlso 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
ProcessBuilderorredirectErrorStream(true); changing thelatter would alter behaviour for every consumer and is discussed in #2 instead.