mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Fix the process CommandLine on Linux (#18710)
This commit is contained in:
@@ -1164,7 +1164,8 @@ namespace System.Management.Automation.Runspaces
|
||||
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,
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user