PPT/服务器启动/start_fixed_server.bat

67 lines
1.7 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
setlocal enabledelayedexpansion
echo 正在启动视频处理系统服务器...
REM 设置环境变量
set PYTHONIOENCODING=utf-8
set PYTHONLEGACYWINDOWSSTDIO=utf-8
REM 检查是否存在必要的文件
if not exist "%~dp0server.py" (
echo 错误: 未找到server.py文件
pause
exit /b 1
)
if not exist "%~dp0pdfkit_patch.py" (
echo 警告: 未找到pdfkit_patch.py文件将创建兼容层...
copy NUL "%~dp0pdfkit_patch.py" > nul
echo 已创建pdfkit_patch.py文件
)
if not exist "%~dp0whisper_patch.py" (
echo 警告: 未找到whisper_patch.py文件将创建兼容层...
copy NUL "%~dp0whisper_patch.py" > nul
echo 已创建whisper_patch.py文件
)
REM 检查端口5001是否被占用
set PORT_FOUND=0
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":5001"') do (
set PID=%%a
set PORT_FOUND=1
goto :found
)
:found
if %PORT_FOUND% equ 1 (
echo 警告: 端口5001已被占用进程ID为: %PID%
choice /c YN /m "是否尝试终止该进程 (Y/N)?"
if !errorlevel! equ 1 (
echo 正在终止进程 %PID%...
taskkill /F /PID %PID%
timeout /t 2 > nul
) else (
echo 请关闭占用端口的程序后再重试。
pause
exit /b 1
)
)
REM 启动服务器
echo 正在启动服务器...
cd /d "%~dp0"
start python server.py
REM 等待服务器启动
echo 正在等待服务器启动...
timeout /t 5 /nobreak > nul
REM 自动打开浏览器
start http://localhost:5001
echo.
echo 如果浏览器没有自动打开,请访问: http://localhost:5001
echo 要停止服务器,请关闭命令行窗口。
pause