これは、grunt
がgrunt.cmd
で起動し、CMD
によって実行されるために発生します。このファイルは、node
にgrunt
を起動します。ここで
はnotepad2.exeあなたの例と同様にCMDから打ち上げ見つける方法の例です:
作男のためにこれを翻訳
# start a CMD which starts notepad2 and then waits on it
$process = Start-Process -PassThru 'cmd.exe' '/c "C:\Program Files\Notepad2\Notepad2.exe"'
# Wait for notepad2 to be launched
Start-Sleep -Seconds 2
# find the children of CMD, and kill the one which is notepad2
(Get-CimInstance win32_process -Filter "ParentProcessId='$($process.Id)' AND Name = 'Notepad2.exe'") | %{ Stop-Process -Id $_.ProcessId}
:
# start Grunt via grunt.cmd
$process = Start-Process grunt -ArgumentList 'serve' -PassThru
# Wait for node to be launched
Start-Sleep -Seconds 2
# find the children of CMD, and kill the one which is node
(Get-CimInstance win32_process -Filter "ParentProcessId='$($process.Id)' AND Name = 'node.exe'") | %{ Stop-Process -Id $_.ProcessId}
'-Filter'と' Where-Object'の両方を使う理由は何ですか? Get-CimInstance -ClassName Win32_Process -Filter ParentProcessId = $($ process.Id)とName = 'notepad.exe'は、両方のファイルを1つの '-Filter'でマージすることができます(WMIはそのプロパティに" Name " " – BartekB
シンタックスを理解する上での怠け者とクエリの少なくとも一部が効率のためにcimフィルタになければなりません – TravisEz13
@BartekBのコメントごとに' -Filter'を更新し、 'Where-Object'を削除しました。 – TravisEz13