Files
perler-lab/stop-dev.bat
T

51 lines
1.8 KiB
Batchfile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
@echo off
chcp 65001 >nul
title 停止 PERLER LAB 开发环境
setlocal enabledelayedexpansion
rem ============================================================
rem PERLER LAB 停止脚本
rem 通过 netstat 查找监听 5173 / 8788 端口的进程并用 taskkill 终止。
rem
rem 为什么用 netstat + taskkill 而不是 wmic:
rem - wmic 已被微软弃用,在 Windows 11 24H2 及更新版本中已移除;
rem - netstat / taskkill 是系统内置命令,无需额外依赖,且对普通用户
rem 进程不需要管理员权限即可终止(Vite / tsx 均为用户态进程)。
rem ============================================================
echo 正在查找并停止 PERLER LAB 相关进程(端口 5173 / 8788)...
echo.
set "KILLED_PIDS="
set "FOUND="
rem 依次检查两个端口
for %%P in (5173 8788) do (
rem 仅匹配 LISTENING 状态的监听进程,避免误杀 TIME_WAIT 残留
for /f "tokens=5" %%A in ('netstat -ano ^| findstr ":%%P " ^| findstr "LISTENING"') do (
rem 同一进程可能同时监听 IPv4 和 IPv6,去重避免重复 taskkill
echo !KILLED_PIDS! | findstr /b /c:" %%A " >nul 2>nul
if errorlevel 1 (
set "FOUND=1"
echo [端口 %%P] 发现进程 PID=%%A,正在终止...
taskkill /F /PID %%A >nul 2>nul
if not errorlevel 1 (
echo [OK] 已终止 PID %%A
set "KILLED_PIDS=!KILLED_PIDS! %%A "
) else (
echo [失败] 终止 PID %%A 失败(可能需要管理员权限)。
)
)
)
)
echo.
if not defined FOUND (
echo 未发现监听 5173 / 8788 端口的进程,开发环境未在运行,无需停止。
) else (
echo 完成。PERLER LAB 开发环境已停止。
)
echo.
pause