Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1155,8 +1155,10 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag<string> errors)
if ($IsWindows) {
(Get-CimInstance Win32_Process -Filter ""ProcessId = $($this.Id)"").CommandLine
} elseif ($IsLinux) {
$rawCmd = Get-Content -LiteralPath ""/proc/$($this.Id)/cmdline""
$rawCmd.Substring(0, $rawCmd.Length - 1) -replace ""`0"", "" ""
$rawCmd = Get-Content -Raw -LiteralPath ""/proc/$($this.Id)/cmdline""
if ($rawCmd.Length -gt 0) {
$rawCmd.Substring(0, $rawCmd.Length - 1) -replace ""`0"", "" ""
}
}
"),
setterScript: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,29 @@ Describe "Get-Process" -Tags "CI" {

$actual | Should -Be $expected
}

It "Should support embedded newline characters in the command line - type check" -Skip:(!$IsLinux) {

# Verify that the CommandLine property returned is of type String and not Object[]:
$expected = "String"

$actual = & "$PSHOME/pwsh" -NoProfile -NoLogo -NonInteractive -Command "(Get-Process -Id `"`$pid`").CommandLine.GetType().Name; `$unusedVar = `"newline character here:`n`""

$actual | Should -Be $expected
}

It "Should support embedded newline characters in the command line - value check" -Skip:(!$IsLinux) {

# Note that we are expecting an array of two strings back, even though the value of the CommandLine property
# itself is a single string (as verified by the previous test). This is because that string contains a newline,
# and once that string is sent to stdout by the subprocess and then read back in by the call operator (&), it
# gets interpreted as two separate lines and therefore gets loaded into an array of two strings:
$expected = @("$PSHOME/pwsh -NoProfile -NoLogo -NonInteractive -Command (Get-Process -Id `"`$pid`").CommandLine; `$unusedVar = `"newline character here:", "`"")

$actual = & "$PSHOME/pwsh" -NoProfile -NoLogo -NonInteractive -Command "(Get-Process -Id `"`$pid`").CommandLine; `$unusedVar = `"newline character here:`n`""

$actual | Should -Be $expected
Comment thread
kevin-hoffman marked this conversation as resolved.
}
}

Describe "Get-Process Formatting" -Tags "Feature" {
Expand Down