| @echo off | |
| setlocal enabledelayedexpansion | |
| cd /d "%~dp0" | |
| rem Force a UTF-8 console + UTF-8 mode in Python so prints with em-dashes and | |
| rem the like don't crash on machines whose console codepage is cp1252 / cp932. | |
| chcp 65001 >nul 2>nul | |
| set "PYTHONUTF8=1" | |
| set "PYTHONIOENCODING=utf-8" | |
| rem Pick a Python launcher. Try py first (works on most python.org installs), | |
| rem then `python`, then `python3`. enabledelayedexpansion + !ERRORLEVEL! is | |
| rem required so each check reads the value AFTER the preceding `where` runs. | |
| set "PYCMD=" | |
| where py >nul 2>nul | |
| if !ERRORLEVEL! EQU 0 set "PYCMD=py" | |
| if not defined PYCMD ( | |
| where python >nul 2>nul | |
| if !ERRORLEVEL! EQU 0 set "PYCMD=python" | |
| ) | |
| if not defined PYCMD ( | |
| where python3 >nul 2>nul | |
| if !ERRORLEVEL! EQU 0 set "PYCMD=python3" | |
| ) | |
| if not defined PYCMD ( | |
| echo [run.bat] No Python found on PATH. | |
| echo [run.bat] Install Python 3.10+ from https://www.python.org/downloads/ | |
| echo [run.bat] During install, tick "Add Python to PATH". | |
| pause | |
| exit /b 1 | |
| ) | |
| echo [run.bat] Using !PYCMD! to launch app.py. | |
| echo [run.bat] First run creates .venv and installs ~500 MB of packages. | |
| echo [run.bat] That can take several minutes; it only happens once. | |
| echo. | |
| !PYCMD! "%~dp0app.py" %* | |
| set "EXITCODE=!ERRORLEVEL!" | |
| if !EXITCODE! NEQ 0 ( | |
| echo. | |
| echo [run.bat] app.py exited with code !EXITCODE!. | |
| pause | |
| ) | |
| endlocal & exit /b %EXITCODE% | |