egg-scripts
egg-scripts copied to clipboard
npm stop在windows 2025上不起效果
windows 2025已经把wmic禁用了,egg-scripts stop还用了wmic来查找eggjs进程,导致错误。有没没有其他办法来杀eggjs进程??????
可以来参与开源贡献
1、我就不直接参与源码贡献了,但是我给你个优化方案和建议。在不支持wmic的新系统,可以用PowerShell执行下面这段代码,达到杀死eggjs相关进程
$processes = Get-CimInstance Win32_Process -Filter "Name='node.exe'" | Where-Object { $_.CommandLine -like "*--title=egg-server*" } if ($processes) { foreach ($proc in $processes) { Write-Output "Terminating process with PID $($proc.ProcessId)" Stop-Process -Id $proc.ProcessId -Force } } else { Write-Output "No matching processes found." }
2、把上面代码可以放入后缀名为:.ps1的文件执行即可。
与egg目录相同目录下,放一个ps1脚本
'''ps1
$packageJsonPath = "$PSScriptRoot\egg\package.json"
$packageJsonContent = Get-Content -Path $packageJsonPath -Raw | ConvertFrom-Json
if ($packageJsonContent.scripts.stop -match '--title=([^"]+)') {
$title = $matches[1]
Write-Output "stopping egg application with --title=$title"
$processes = Get-Process -Name "node" | Where-Object { $_.CommandLine -like "*$title*" -and $_.CommandLine -like "*start-cluster*" }
foreach ($process in $processes) {
Stop-Process -Id $process.Id -Force
}
}
Start-Sleep -Seconds 5
Get-Process node | Where-Object { $_.Name -eq "node" -and ($_.Path -like "*egg-cluster*" -or $_.Path -like "*egg-scripts*") } | Stop-Process -Force
Write-Output "stopped"
'''