mardi 6 décembre 2016

Batch Script fails in IF statement

My batch script is failing in the second if state of :nbig. (I have found this out using @echo after each statement). However, the SET statement within the if succeed if run normally, as does the if statement with an @echo inside. This is very peculiar and I can't see what I have done wrong.

My code is here:

:: Set the day and night values
set /A nighttemp = 2700
set /A daytemp = 6500
:: Set Transition Duration 
set /A transitionduration = 60
:: Set times in minutes from midnight
set /A tnight = 1380
set /A tday = 480

For /f "tokens=1-4 delims=/:." %%a in ("%TIME%") do (
    SET /A HH24=%%a
    SET /A MI=%%b
    SET /A SS=%%c
    SET /A FF=%%d
)

SET /A mins = %HH24%*60 + %MI%
SET /A tdaywindow = %tday% + 60
SET /A tnightwindow = %tnight% + 60

if %tnight% GEQ %tday% ( GOTO NBIG) 
if %tnight% LSS %tday% ( GOTO DBIG)

pause

:NBIG

if %mins% LSS %tday% ( SET /A temp = %nighttemp% )
if %mins% LSS %tdaywindow% ( SET /A temp = (%daytemp% - %nighttemp%)*((%mins% - %tday%)/60) + %nighttemp% )
if %mins% LSS %tnight%( SET /A temp = %daytemp% )
if %mins% LSS %tnightwindow%( SET /A temp =  (%nighttemp% - %daytemp%)*((%mins% - %tnight%)/60) + %daytemp% )
GOTO ENDING

:DBIG
if %mins% LSS %tnight%( SET /A temp = %daytemp% )
if %mins% LSS %tnightwindow% ( SET /A temp = (%nighttemp% - %daytemp%)*((%mins% - %tnight%)/60) + %daytemp%)
if %mins% LSS %tday% ( SET /A temp = %nighttemp% )
if %mins% LSS %tdaywindow% ( SET /A temp = (%daytemp% - %nighttemp%)*((%mins% - %tday%)/60) + %nighttemp% )
GOTO ENDING

:ENDING
@echo %temp%
pause

::%~dp0\redshift.exe -O %temp%

A correctly running program should @echo the value of temp, however it errors.

(Aside: This is to run the redshift program with custom times...)

Aucun commentaire:

Enregistrer un commentaire