From bb4c8c07f80a9d5503655e38f5073adce663aaa5 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Sun, 18 Sep 2022 09:33:20 -0400 Subject: [PATCH] Fix cmd_or_ps.ps1 script with pwsh7 gwmi command does not exist any more and is replaced by Get-CimInstance. See https://github.com/PowerShell/PowerShell/issues/4766. While at it, use a do..while loop to avoid duplicated lines. Fixes: #10820 --- mesonbuild/scripts/cmd_or_ps.ps1 | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mesonbuild/scripts/cmd_or_ps.ps1 b/mesonbuild/scripts/cmd_or_ps.ps1 index 1d677d9c6..96c32e29d 100644 --- a/mesonbuild/scripts/cmd_or_ps.ps1 +++ b/mesonbuild/scripts/cmd_or_ps.ps1 @@ -1,22 +1,17 @@ # Copied from GStreamer project # Author: Seungha Yang +# Xavier Claessens $i=1 -$ppid=(gwmi win32_process -Filter "processid='$pid'").parentprocessid -$pname=(Get-Process -id $ppid).Name -While($true) { +$ppid=$PID +do { + $ppid=(Get-CimInstance Win32_Process -Filter "ProcessId=$ppid").parentprocessid + $pname=(Get-Process -id $ppid).Name if($pname -eq "cmd" -Or $pname -eq "powershell" -Or $pname -eq "pwsh") { Write-Host ("{0}.exe" -f $pname) Break } - + # not found yet, find grand parent # 10 times iteration seems to be sufficient - if($i -gt 10) { - Break - } - - # not found yet, find grand parant - $ppid=(gwmi win32_process -Filter "processid='$ppid'").parentprocessid - $pname=(Get-Process -id $ppid).Name $i++ -} +} while ($i -lt 10)