Skip to content
Merged
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 @@ -1164,7 +1164,8 @@ private void Process_Types_Ps1Xml(string filePath, ConcurrentBag<string> errors)
if ($IsWindows) {
(Get-CimInstance Win32_Process -Filter ""ProcessId = $($this.Id)"").CommandLine
} elseif ($IsLinux) {
Get-Content -LiteralPath ""/proc/$($this.Id)/cmdline""
$rawCmd = Get-Content -LiteralPath ""/proc/$($this.Id)/cmdline""
$rawCmd.Substring(0, $rawCmd.Length - 1) -replace ""`0"", "" ""
}
"),
setterScript: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,25 @@ Describe "Get-Process" -Tags "CI" {
}

It "Should return CommandLine property" -Skip:($IsMacOS) {
$command = "(Get-Process -Id `$pid).CommandLine"
$result = & "$PSHOME/pwsh" -NoProfile -NonInteractive -Command $command
$result | Should -BeLike "*$command*"
if ($IsWindows) {
# Windows will convert the bound parameters and quote them if it
# contains whitespace. Any inner double quotes are escaped with \".
$expected = "`"$PSHOME\pwsh.exe`" -NoProfile -NoLogo -NonInteractive -Command `"(Get-Process -Id \`"`$pid\`").CommandLine`""

$actual = & {
$PSNativeCommandArgumentPassing = 'Windows'
& $PSHOME/pwsh -NoProfile -NoLogo -NonInteractive -Command '(Get-Process -Id "$pid").CommandLine'
}
} else {
# Linux passes arguments as they are bound. As there is no actual
# command line string, pwsh just joins each array with a space
# without attempting to use some sort of quoting rule.
$expected = "$PSHOME/pwsh -NoProfile -NoLogo -NonInteractive -Command (Get-Process -Id `"`$pid`").CommandLine"

$actual = & "$PSHOME/pwsh" -NoProfile -NoLogo -NonInteractive -Command '(Get-Process -Id "$pid").CommandLine'
}

$actual | Should -Be $expected
}
}

Expand Down