-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_live_html_editor.bat
More file actions
113 lines (100 loc) · 2.4 KB
/
Copy pathrun_live_html_editor.bat
File metadata and controls
113 lines (100 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
@echo off
pushd "%~dp0"
setlocal EnableExtensions
REM run_live_html_editor.bat 1 -> start server + open browser
REM run_live_html_editor.bat 0 -> stop server
set "PORT=8000"
set "URL=http://localhost:%PORT%/live_html_editor/live-html-editor.html"
set "PIDFILE=%~dp0live_html_editor.pid"
set "error=0"
if "%~1"=="" goto :MENU
if "%~1"=="1" goto :START
if "%~1"=="2" goto :STOP
echo Usage:
echo %~nx0 1 ^(start^)
echo %~nx0 2 ^(stop^)
echo %~nx0 ^(menu^)
set "error=0"
goto :EXIT
:MENU
cls
ECHO -------------------------
ECHO 1. Start Live HTML Editor
ECHO 2. Stop Server/App
ECHO 3. Exit
ECHO -------------------------
set choice=
set /p choice=Please select (1/2/3):
if '%choice%'=='' goto :MENU
if '%choice%'=='1' goto :START
if '%choice%'=='2' goto :STOP
if '%choice%'=='3' goto :EXIT
Goto :MENU
:START
where python >nul 2>nul
if errorlevel 1 (
echo.
echo Python was not found on PATH.
echo Install Python 3 from https://www.python.org/ and try again.
set "error=1"
goto :EXIT
)
REM If something is already on that port, don't start a second server.
netstat -ano | findstr /R /C:":%PORT% .*LISTENING" >nul
if not errorlevel 1 (
echo.
echo Port %PORT% is already in use.
echo If this is an old LIVE server, run:
echo %~nx0 0
set "error=1"
goto :EXIT
)
echo.
echo Starting server on port %PORT% ...
REM Start server via PowerShell so we can capture its PID.
powershell -NoProfile -Command "$p = Start-Process -PassThru -WindowStyle Minimized -WorkingDirectory '%~dp0' -FilePath cmd.exe -ArgumentList '/c','python -m http.server %PORT%'; Set-Content -Encoding ASCII -Path '%PIDFILE%' -Value $p.Id;" >nul
REM Give the server a moment to start
timeout /t 1 /nobreak >nul
echo Opening %URL%
start "" "%URL%"
echo.
echo To stop the server later, run:
echo %~nx0 0
set "error=0"
timeout /t 5
goto :MENU
:STOP
if not exist "%PIDFILE%" (
echo.
echo No PID file found: %PIDFILE%
echo Server may already be stopped.
set "error=1"
goto :EXIT
)
set /p SERVERPID=<"%PIDFILE%"
if "%SERVERPID%"=="" (
echo.
echo PID file was empty.
del "%PIDFILE%" >nul 2>nul
set "error=1"
goto :EXIT
)
echo.
echo Stopping server PID %SERVERPID% ...
taskkill /PID %SERVERPID% /F >nul 2>nul
if errorlevel 1 (
echo.
echo Failed to stop PID %SERVERPID% ...
) else (
echo.
echo Server stopped.
)
del "%PIDFILE%" >nul 2>nul
set "error=0"
goto :MENU
:EXIT
echo.
echo Goodbye!
timeout /t 5
endlocal
exit /b %error%