簡體   English   中英

Powershell - Get-Process 的 ProcessName 在 macOS 上被截斷

[英]Powershell - Get-Process's ProcessName is truncated on macOS

我在 macOS 12.5 上使用 Powershell 7.2.5。 我打開了谷歌瀏覽器並運行了Get-Process google* ,並被截斷了 ProcessName:

gps google*                    

 NPM(K)    PM(M)      WS(M)     CPU(s)      Id  SI ProcessName
 ------    -----      -----     ------      --  -- -----------
      0     0.00     626.36   5,529.29   33973   1 Google Chrome
      0     0.00     124.94   2,870.73   33993   1 Google Chrome H

Google Chrome H應該是Google Chrome Helper或更長的東西。

gps | sort-object {$_.ProcessName.length} gps | sort-object {$_.ProcessName.length}表明所有進程名都被截斷為 15 個字符。

如何在不截斷的情況下制作Get-Process output?

我閱讀了Get-Process的幫助並嘗試將 pipe 將 output 轉換為Format-CustomFormat-List ProcessName -Force ,但這些技巧都沒有奏效。

Unfortunately, this is not a formatting problem : At least up to the .NET version underlying PowerShell Core 7.3.0-preview.6, .NET, .NET 7.0.0-preview.6.22324.4, the .ProcessName property value is limited to 15 chars .

這是一個已知問題,並且有一個已知的修復程序,但還沒有人加緊實施它 - 請參閱GitHub 問題 #52860

A - 計算成本高 -解決方法是通過計算屬性使用對本機ps實用程序的調用:

Get-Process google* | 
  Select-Object Id, 
                @{ n='ProcessName'; e={ Split-Path -Leaf (ps -p $_.Id -o comm=) }

注意:以上僅報告進程 ID 和(完整)進程名稱。

如果您想要與默認情況下相同的顯示列,則需要做更多的工作,僅使用完整的進程名稱:

Get-Process google* | ForEach-Object {
  $copy = $_ | Select-Object *
  $copy.ProcessName = Split-Path -Leaf (ps -p $_.Id -o comm=)
  $copy.pstypenames.Insert(0, 'System.Diagnostics.Process')
  $copy
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM