Skip to content

Fix to properly handle EOL chars in the Get-Process CommandLine prope…#27501

Open
kevin-hoffman wants to merge 1 commit into
PowerShell:masterfrom
kevin-hoffman:bugfix/27499-commandline-support-embedded-eol-chars
Open

Fix to properly handle EOL chars in the Get-Process CommandLine prope…#27501
kevin-hoffman wants to merge 1 commit into
PowerShell:masterfrom
kevin-hoffman:bugfix/27499-commandline-support-embedded-eol-chars

Conversation

@kevin-hoffman
Copy link
Copy Markdown

PR Summary

Fixes an issue with the Get-Process CommandLine property where it gets truncated if a newline character is embedded in the command line being parsed.

PR Context

Fixes #27499

PR Checklist

@kevin-hoffman kevin-hoffman requested a review from a team as a code owner May 22, 2026 15:18
Copilot AI review requested due to automatic review settings May 22, 2026 15:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds Linux-focused coverage for Get-Process.CommandLine when the command line contains embedded newline characters, and adjusts Linux command line extraction to return a single string instead of an array.

Changes:

  • Added Pester tests to validate CommandLine type (String) and behavior when the command line contains a newline.
  • Updated Linux CommandLine generation to use Get-Content -Raw for /proc/<pid>/cmdline so the result stays a single string.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/powershell/Modules/Microsoft.PowerShell.Management/Get-Process.Tests.ps1 Adds Linux-only tests for embedded newline behavior and type consistency of CommandLine.
src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs Updates Linux process command line reading to use -Raw to avoid Object[] output.
Comments suppressed due to low confidence (1)

src/System.Management.Automation/engine/TypeTable_Types_Ps1Xml.cs:1

  • With -Raw, $rawCmd will be an empty string when /proc/<pid>/cmdline is empty (common for some kernel threads / certain processes). In that case, $rawCmd.Length - 1 becomes -1 and Substring(0, -1) will throw. Prefer trimming the trailing null safely (e.g., TrimEnd([char]0)), or only applying Substring when $rawCmd.Length -gt 0 and the last character is 0.
// Copyright (c) Microsoft Corporation.

@kevin-hoffman
Copy link
Copy Markdown
Author

kevin-hoffman commented May 22, 2026

@microsoft-github-policy-service agree

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.

Get-Process CommandLine property gets truncated if it contains a newline character on Linux

2 participants