新增 stop.bat/ps1/sh,并写入本地开发规则:停服务用脚本、停后复核端口。 Co-authored-by: Cursor <cursoragent@cursor.com>
25 lines
677 B
PowerShell
25 lines
677 B
PowerShell
# 按 Listen 端口终止进程树(含子进程)。默认 :3000 前端 / :3001 后端。
|
||
# 由 stop.bat 调用;也可直接:powershell -File stop.ps1
|
||
|
||
param(
|
||
[int[]]$Ports = @(3000, 3001)
|
||
)
|
||
|
||
$ErrorActionPreference = 'SilentlyContinue'
|
||
|
||
foreach ($port in $Ports) {
|
||
$pids = @(
|
||
Get-NetTCPConnection -LocalPort $port -State Listen |
|
||
Select-Object -ExpandProperty OwningProcess -Unique
|
||
)
|
||
if (-not $pids -or $pids.Count -eq 0) {
|
||
Write-Host " :$port 空闲"
|
||
continue
|
||
}
|
||
foreach ($procId in $pids) {
|
||
if ($procId -le 0) { continue }
|
||
Write-Host " :$port -> PID $procId (含子进程)"
|
||
& taskkill.exe /T /F /PID $procId | Out-Null
|
||
}
|
||
}
|