@echo off chcp 65001 >nul title subtitle-studio 启动器 setlocal REM ===== subtitle-studio 后台启动(无窗口)===== set SCRIPT_DIR=%~dp0 set PROJECT_ROOT=%SCRIPT_DIR%.. set APP_DIR=%PROJECT_ROOT%\src set PYTHON=D:\ProgramData\anaconda3\envs\py312_cuda\python.exe set PORT=8788 set LOG_DIR=%PROJECT_ROOT%\logs if not exist "%PYTHON%" ( echo [错误] 找不到 Python 环境: %PYTHON% pause exit /b 1 ) netstat -ano | findstr ":%PORT%" | findstr "LISTENING" >nul 2>&1 if %errorlevel%==0 ( echo subtitle-studio 已在运行: http://127.0.0.1:%PORT% start http://127.0.0.1:%PORT% exit /b 0 ) if not exist "%LOG_DIR%" mkdir "%LOG_DIR%" REM 后台启动:用 cmd /c 包装重定向,start 本身不阻塞 cd /d "%PROJECT_ROOT%" start "subtitle-studio-server" /min cmd /c ""%PYTHON%" -m uvicorn substudio.main:app --host 127.0.0.1 --port %PORT% --app-dir "%APP_DIR%" >"%LOG_DIR%\server.log" 2>&1" REM 等待端口就绪 set /a tries=0 :waitloop set /a tries+=1 if %tries% GTR 20 goto timeout netstat -ano | findstr ":%PORT%" | findstr "LISTENING" >nul 2>&1 if %errorlevel%==0 goto ready timeout /t 1 /nobreak >nul goto waitloop :ready echo. echo ✅ subtitle-studio 已启动 echo http://127.0.0.1:%PORT% echo 日志: %LOG_DIR%\server.log echo. start http://127.0.0.1:%PORT% exit /b 0 :timeout echo. echo ⚠️ 启动超时,请查看日志: %LOG_DIR%\server.log pause exit /b 1