Grio43 commited on
Commit
c53ebec
·
verified ·
1 Parent(s): 071ea55

Fix run.bat: convert LF to CRLF line endings so CMD parses commands correctly

Browse files

Without CRLF, CMD mis-tokenized setlocal/cd/set/rem and skipped delayed-expansion init, breaking !PYCMD! and !EXITCODE! expansion.

Files changed (1) hide show
  1. web_interface/run.bat +84 -84
web_interface/run.bat CHANGED
@@ -1,84 +1,84 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
- cd /d "%~dp0"
4
-
5
- rem Force a UTF-8 console + UTF-8 mode in Python so prints with em-dashes and
6
- rem the like don't crash on machines whose console codepage is cp1252 / cp932.
7
- chcp 65001 >nul 2>nul
8
- set "PYTHONUTF8=1"
9
- set "PYTHONIOENCODING=utf-8"
10
-
11
- rem Pick a Python launcher. Order:
12
- rem 1. .pyenv\python.exe — portable Python downloaded by a previous run
13
- rem 2. py / python / python3 — user's system Python
14
- rem 3. Download a portable Python on the fly (no admin, no PATH changes)
15
- set "PYCMD="
16
-
17
- if exist "%~dp0.pyenv\python.exe" (
18
- set "PYCMD=%~dp0.pyenv\python.exe"
19
- goto :launch
20
- )
21
-
22
- where py >nul 2>nul
23
- if !ERRORLEVEL! EQU 0 set "PYCMD=py"
24
-
25
- if not defined PYCMD (
26
- where python >nul 2>nul
27
- if !ERRORLEVEL! EQU 0 set "PYCMD=python"
28
- )
29
-
30
- if not defined PYCMD (
31
- where python3 >nul 2>nul
32
- if !ERRORLEVEL! EQU 0 set "PYCMD=python3"
33
- )
34
-
35
- if defined PYCMD goto :launch
36
-
37
- echo [run.bat] No Python detected on this machine.
38
- echo [run.bat] Downloading a portable Python (~30 MB) into .pyenv\ next to this script.
39
- echo [run.bat] Nothing is installed system-wide; delete .pyenv\ to remove it.
40
- echo.
41
-
42
- powershell -NoProfile -ExecutionPolicy Bypass -Command ^
43
- "$ErrorActionPreference='Stop';" ^
44
- "$ver='3.12.7';" ^
45
- "$dest='%~dp0.pyenv';" ^
46
- "$zip=Join-Path $env:TEMP 'oppai-py-embed.zip';" ^
47
- "[void](New-Item -ItemType Directory -Force -Path $dest);" ^
48
- "Invoke-WebRequest -UseBasicParsing -Uri \"https://www.python.org/ftp/python/$ver/python-$ver-embed-amd64.zip\" -OutFile $zip;" ^
49
- "Expand-Archive -Path $zip -DestinationPath $dest -Force;" ^
50
- "Remove-Item $zip -Force"
51
-
52
- if !ERRORLEVEL! NEQ 0 (
53
- echo.
54
- echo [run.bat] Failed to download portable Python.
55
- echo [run.bat] Check your internet connection, or install Python 3.10-3.12
56
- echo from https://www.python.org/downloads/ ^(tick "Add Python to PATH"^)
57
- echo and re-run this script.
58
- pause
59
- exit /b 1
60
- )
61
-
62
- if not exist "%~dp0.pyenv\python.exe" (
63
- echo [run.bat] Portable Python download finished but python.exe is missing.
64
- echo [run.bat] Try deleting .pyenv\ and re-running, or install Python manually.
65
- pause
66
- exit /b 1
67
- )
68
-
69
- set "PYCMD=%~dp0.pyenv\python.exe"
70
-
71
- :launch
72
- echo [run.bat] Using !PYCMD! to launch app.py.
73
- echo [run.bat] First run installs ~500 MB of packages; that only happens once.
74
- echo.
75
-
76
- "!PYCMD!" "%~dp0app.py" %*
77
- set "EXITCODE=!ERRORLEVEL!"
78
-
79
- if !EXITCODE! NEQ 0 (
80
- echo.
81
- echo [run.bat] app.py exited with code !EXITCODE!.
82
- pause
83
- )
84
- endlocal & exit /b %EXITCODE%
 
1
+ @echo off
2
+ setlocal enabledelayedexpansion
3
+ cd /d "%~dp0"
4
+
5
+ rem Force a UTF-8 console + UTF-8 mode in Python so prints with em-dashes and
6
+ rem the like don't crash on machines whose console codepage is cp1252 / cp932.
7
+ chcp 65001 >nul 2>nul
8
+ set "PYTHONUTF8=1"
9
+ set "PYTHONIOENCODING=utf-8"
10
+
11
+ rem Pick a Python launcher. Order:
12
+ rem 1. .pyenv\python.exe — portable Python downloaded by a previous run
13
+ rem 2. py / python / python3 — user's system Python
14
+ rem 3. Download a portable Python on the fly (no admin, no PATH changes)
15
+ set "PYCMD="
16
+
17
+ if exist "%~dp0.pyenv\python.exe" (
18
+ set "PYCMD=%~dp0.pyenv\python.exe"
19
+ goto :launch
20
+ )
21
+
22
+ where py >nul 2>nul
23
+ if !ERRORLEVEL! EQU 0 set "PYCMD=py"
24
+
25
+ if not defined PYCMD (
26
+ where python >nul 2>nul
27
+ if !ERRORLEVEL! EQU 0 set "PYCMD=python"
28
+ )
29
+
30
+ if not defined PYCMD (
31
+ where python3 >nul 2>nul
32
+ if !ERRORLEVEL! EQU 0 set "PYCMD=python3"
33
+ )
34
+
35
+ if defined PYCMD goto :launch
36
+
37
+ echo [run.bat] No Python detected on this machine.
38
+ echo [run.bat] Downloading a portable Python (~30 MB) into .pyenv\ next to this script.
39
+ echo [run.bat] Nothing is installed system-wide; delete .pyenv\ to remove it.
40
+ echo.
41
+
42
+ powershell -NoProfile -ExecutionPolicy Bypass -Command ^
43
+ "$ErrorActionPreference='Stop';" ^
44
+ "$ver='3.12.7';" ^
45
+ "$dest='%~dp0.pyenv';" ^
46
+ "$zip=Join-Path $env:TEMP 'oppai-py-embed.zip';" ^
47
+ "[void](New-Item -ItemType Directory -Force -Path $dest);" ^
48
+ "Invoke-WebRequest -UseBasicParsing -Uri \"https://www.python.org/ftp/python/$ver/python-$ver-embed-amd64.zip\" -OutFile $zip;" ^
49
+ "Expand-Archive -Path $zip -DestinationPath $dest -Force;" ^
50
+ "Remove-Item $zip -Force"
51
+
52
+ if !ERRORLEVEL! NEQ 0 (
53
+ echo.
54
+ echo [run.bat] Failed to download portable Python.
55
+ echo [run.bat] Check your internet connection, or install Python 3.10-3.12
56
+ echo from https://www.python.org/downloads/ ^(tick "Add Python to PATH"^)
57
+ echo and re-run this script.
58
+ pause
59
+ exit /b 1
60
+ )
61
+
62
+ if not exist "%~dp0.pyenv\python.exe" (
63
+ echo [run.bat] Portable Python download finished but python.exe is missing.
64
+ echo [run.bat] Try deleting .pyenv\ and re-running, or install Python manually.
65
+ pause
66
+ exit /b 1
67
+ )
68
+
69
+ set "PYCMD=%~dp0.pyenv\python.exe"
70
+
71
+ :launch
72
+ echo [run.bat] Using !PYCMD! to launch app.py.
73
+ echo [run.bat] First run installs ~500 MB of packages; that only happens once.
74
+ echo.
75
+
76
+ "!PYCMD!" "%~dp0app.py" %*
77
+ set "EXITCODE=!ERRORLEVEL!"
78
+
79
+ if !EXITCODE! NEQ 0 (
80
+ echo.
81
+ echo [run.bat] app.py exited with code !EXITCODE!.
82
+ pause
83
+ )
84
+ endlocal & exit /b %EXITCODE%