dev
This commit is contained in:
25
stop_domain_web.ps1
Normal file
25
stop_domain_web.ps1
Normal file
@@ -0,0 +1,25 @@
|
||||
$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))
|
||||
Reference in New Issue
Block a user