# 后端服务启动脚本 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