@echo off 
:: RobotTeclado Launcher con logs 
setlocal enabledelayedexpansion 
 
:: Detectar Java 
if exist "%~dp0\..\Java\bin\java.exe" ( 
    set JAVA_CMD=%~dp0\..\Java\bin\java.exe 
) 
if not exist "%~dp0\..\Java\bin\java.exe" ( 
    set JAVA_CMD=java 
) 
 
:: Crear log con fecha 
for /f "usebackq delims=" %%i in (`powershell -command "Get-Date -Format 'yyyyMMdd_HHmmss'"`) do set TIMESTAMP=%%i 
set LOG_FILE=%~dp0\logs\robot_!TIMESTAMP!.log 
 
:: Crear carpeta de logs 
if not exist "%~dp0\logs" mkdir "%~dp0\logs" 
 
:: Ejecutar 
echo --- INICIO: %date% %time% --- > "!LOG_FILE!" 
cd /d "%~dp0" 
"!JAVA_CMD!" -cp "RobotTeclado.jar;lib\*" es.alfamicroges.robot.Operacion "robot.properties" >> "!LOG_FILE!" 2>&1 
echo --- FIN: %date% %time% --- >> "!LOG_FILE!" 
 
:: Rotar logs (guardar 10) 
pushd "%~dp0\logs" 
for /f "skip=10 delims=" %%f in ('dir /b /o-d robot_*.log 2>nul') do del "%%f" 2>nul 
popd 
