73 lines
1.9 KiB
Batchfile
73 lines
1.9 KiB
Batchfile
@echo off
|
|
chcp 936
|
|
setlocal enabledelayedexpansion
|
|
|
|
:: Debug mode
|
|
set DEBUG=0
|
|
|
|
:: Configuration
|
|
set APP_NAME=ShengShengBuXi.ConsoleApp.exe
|
|
set LOG_FILE=%~dp0ShengShengBuXi.log
|
|
set RESTART_DELAY=0
|
|
|
|
:: Create log file
|
|
echo [%date% %time%] Batch file started > "%LOG_FILE%"
|
|
echo [%date% %time%] Current directory: %cd% >> "%LOG_FILE%"
|
|
echo [%date% %time%] Batch file directory: %~dp0 >> "%LOG_FILE%"
|
|
|
|
echo [INFO] Checking environment...
|
|
echo [INFO] Current directory: %cd%
|
|
echo [INFO] Batch file directory: %~dp0
|
|
echo [INFO] Checking program file...
|
|
|
|
:: Check if program exists
|
|
if not exist "%~dp0%APP_NAME%" (
|
|
echo [ERROR] Cannot find %APP_NAME%
|
|
echo [ERROR] Please make sure the batch file and program are in the same directory
|
|
echo [INFO] Directory listing:
|
|
dir
|
|
echo [ERROR] Program file not found >> "%LOG_FILE%"
|
|
pause
|
|
exit /b 1
|
|
)
|
|
|
|
echo [INFO] Program file check passed
|
|
echo [INFO] Program file check passed >> "%LOG_FILE%"
|
|
|
|
:restart
|
|
:: Debug info
|
|
if defined DEBUG (
|
|
echo [DEBUG] Current directory: %cd%
|
|
echo [DEBUG] Program path: %~dp0%APP_NAME%
|
|
echo [DEBUG] Log path: %LOG_FILE%
|
|
echo [INFO] Preparing to start program...
|
|
echo [INFO] Preparing to start program... >> "%LOG_FILE%"
|
|
)
|
|
|
|
:: Log start
|
|
echo [%date% %time%] Starting %APP_NAME% >> "%LOG_FILE%"
|
|
|
|
:: Start program
|
|
echo [INFO] Starting program...
|
|
echo [INFO] Starting program... >> "%LOG_FILE%"
|
|
|
|
:: Run program with full path
|
|
"%~dp0%APP_NAME%" >> "%LOG_FILE%" 2>&1
|
|
|
|
:: Check exit status
|
|
set EXIT_CODE=%errorlevel%
|
|
echo [%date% %time%] Program exited with code: !EXIT_CODE! >> "%LOG_FILE%"
|
|
|
|
if !EXIT_CODE! neq 0 (
|
|
echo [WARNING] Program exited abnormally >> "%LOG_FILE%"
|
|
echo [WARNING] Program exited with code: !EXIT_CODE!
|
|
echo [INFO] Please check log file: %LOG_FILE%
|
|
)
|
|
|
|
:: Restart delay
|
|
echo [%date% %time%] Restarting in %RESTART_DELAY% seconds... >> "%LOG_FILE%"
|
|
echo [INFO] Restarting in %RESTART_DELAY% seconds...
|
|
timeout /t %RESTART_DELAY% /nobreak >nul
|
|
|
|
goto restart
|
|
|