26 lines
879 B
PowerShell
26 lines
879 B
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$webPort = if ($env:WEB_PORT) { $env:WEB_PORT } else { '3200' }
|
|
|
|
$processIds = @()
|
|
$targets = Get-CimInstance Win32_Process | Where-Object {
|
|
$_.CommandLine -like "*vite*--host 0.0.0.0 --port $webPort*" -or
|
|
$_.CommandLine -like "*npm*run dev*--port $webPort*"
|
|
}
|
|
$processIds += $targets.ProcessId
|
|
$listeners = Get-NetTCPConnection -LocalPort ([int]$webPort) -State Listen -ErrorAction SilentlyContinue
|
|
if ($listeners) {
|
|
$processIds += $listeners.OwningProcess
|
|
}
|
|
$processIds = $processIds | Where-Object { $_ } | Select-Object -Unique
|
|
|
|
if (-not $processIds) {
|
|
Write-Output 'domain-web 当前没有运行中的进程'
|
|
exit 0
|
|
}
|
|
|
|
foreach ($processId in $processIds) {
|
|
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Output ("domain-web 已停止,进程数: " + (($processIds | Measure-Object).Count))
|