File size: 770 Bytes
551658a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 后端服务启动脚本
param(
    [int]$Port = 8000
)

Write-Host "正在检查端口 $Port 是否被占用..." -ForegroundColor Cyan

# 查找占用端口的进程
$process = Get-NetTCPConnection -LocalPort $Port -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess -First 1

if ($process) {
    Write-Host "端口 $Port 被进程 PID: $process 占用" -ForegroundColor Yellow
    Write-Host "正在终止进程..." -ForegroundColor Yellow
    Stop-Process -Id $process -Force -ErrorAction SilentlyContinue
    Start-Sleep -Seconds 1
    Write-Host "进程已终止" -ForegroundColor Green
} else {
    Write-Host "端口 $Port 可用" -ForegroundColor Green
}

Write-Host "`n正在启动后端服务..." -ForegroundColor Cyan
python main.py