MilliSim/restart.bat

81 lines
2.6 KiB
Batchfile
Raw Permalink 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 2>&1
cd /d "%~dp0"
title MilliSim4 前后端重启工具
echo ========================================
echo MilliSim4 前后端重启脚本
echo 后端端口: 5000 前端端口: 5173
echo ========================================
echo.
REM ===== 1. 停止现有进程 =====
echo [1/4] 检查并停止现有进程...
REM 停止后端进程(端口 5000
set "backend_killed=0"
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":5000 " ^| findstr "LISTENING"') do (
echo - 停止后端进程 PID: %%a
taskkill /F /PID %%a >nul 2>&1
set "backend_killed=1"
)
REM 停止前端进程(端口 5173
set "frontend_killed=0"
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":5173 " ^| findstr "LISTENING"') do (
echo - 停止前端进程 PID: %%a
taskkill /F /PID %%a >nul 2>&1
set "frontend_killed=1"
)
REM 额外:杀掉所有 MilliSim.Api.exe 进程(防止端口不在监听但进程仍存在)
taskkill /F /IM MilliSim.Api.exe >nul 2>&1
if "%backend_killed%"=="0" if "%frontend_killed%"=="0" (
echo - 没有发现正在运行的进程
) else (
echo - 已停止相关进程,等待端口释放...
timeout /t 2 /nobreak >nul
)
echo.
REM ===== 2. 启动后端 =====
echo [2/4] 启动后端服务 (端口 5000)...
if not exist "%~dp0backend\MilliSim.Api\MilliSim.Api.csproj" (
echo [错误] 未找到后端项目文件!
echo 预期路径: %~dp0backend\MilliSim.Api\MilliSim.Api.csproj
pause
exit /b 1
)
start "MilliSim4 - Backend (5000)" cmd /k "cd /d %~dp0backend\MilliSim.Api && dotnet run"
echo 后端已在新窗口启动,等待初始化...
REM 等待后端启动(给 dotnet build + run 留时间)
timeout /t 6 /nobreak >nul
REM ===== 3. 启动前端 =====
echo [3/4] 启动前端服务 (端口 5173)...
if not exist "%~dp0frontend\package.json" (
echo [错误] 未找到前端项目文件!
echo 预期路径: %~dp0frontend\package.json
pause
exit /b 1
)
start "MilliSim4 - Frontend (5173)" cmd /k "cd /d %~dp0frontend && npm run dev"
echo 前端已在新窗口启动
REM ===== 4. 完成 =====
echo [4/4] 启动完成!
echo.
echo ========================================
echo 服务地址:
echo 后端 API: http://localhost:5000
echo 前端页面: http://localhost:5173
echo ========================================
echo.
echo 注意事项:
echo - 前端首次启动需要编译,请等待出现 "Local:" 提示后再访问
echo - 如需停止服务,关闭弹出的两个窗口即可
echo - 后端日志在弹出的 "Backend" 窗口中查看
echo.
pause