@echo off REM ============================================================================ REM Atomizer Script Runner — Run any Python script with result capture REM ============================================================================ REM Usage: REM run_script.bat path\to\script.py [args...] REM REM Results sync back to Mario via Syncthing in test_results/ REM ============================================================================ setlocal enabledelayedexpansion set "ATOMIZER_ROOT=%~dp0" set "RESULTS_DIR=%ATOMIZER_ROOT%test_results" set "SCRIPT=%~1" if "%SCRIPT%"=="" ( echo Usage: run_script.bat path\to\script.py [args...] pause exit /b 1 ) REM Timestamp for /f %%i in ('python -c "from datetime import datetime; print(datetime.now().strftime('%%Y-%%m-%%d_%%H-%%M-%%S'))"') do set "TIMESTAMP=%%i" set "LOG_FILE=%RESULTS_DIR%\script_%TIMESTAMP%.log" set "RUN_FILE=%RESULTS_DIR%\script_%TIMESTAMP%.json" if not exist "%RESULTS_DIR%" mkdir "%RESULTS_DIR%" echo. echo ============================================================================ echo Running: %SCRIPT% echo %date% %time% echo ============================================================================ echo. cd /d "%ATOMIZER_ROOT%" REM Shift past first arg to get remaining args set "EXTRA_ARGS=" shift :argloop if not "%~1"=="" ( set "EXTRA_ARGS=!EXTRA_ARGS! %~1" shift goto argloop ) REM Run the script python "%SCRIPT%" %EXTRA_ARGS% > "%LOG_FILE%" 2>&1 set "EXIT_CODE=!errorlevel!" REM Also echo to console type "%LOG_FILE%" echo. echo ============================================================================ echo Exit code: %EXIT_CODE% REM Generate result JSON python -c " import json, os from datetime import datetime with open(r'%LOG_FILE%', 'r', encoding='utf-8', errors='replace') as f: log = f.read() # Grab last 50 lines for quick review lines = log.strip().split('\n') tail = lines[-50:] if len(lines) > 50 else lines result = { 'timestamp': datetime.now().isoformat(), 'type': 'script', 'script': '%SCRIPT%', 'args': '%EXTRA_ARGS%'.strip(), 'exit_code': int('%EXIT_CODE%'), 'status': 'OK' if int('%EXIT_CODE%') == 0 else 'ERROR', 'output_tail': tail, 'log_file': os.path.basename(r'%LOG_FILE%'), 'total_lines': len(lines) } with open(r'%RUN_FILE%', 'w') as f: json.dump(result, f, indent=2) " echo Results saved. Will sync to Mario via Syncthing. echo ============================================================================ pause