Episode about 2 billion of delayedexpansion
Within a block statement (a parenthesised series of statements), the entire block is parsed and then executed. Any %var% within the block will be replaced by that variable's value at the time the block is parsed - before the block is executed - the same thing applies to a FOR ... DO (block).
Hence, IF (something) else (somethingelse) will be executed using the values of %variables% at the time the IF is encountered.
Two common ways to overcome this are 1) to use setlocal enabledelayedexpansion and use !var! in place of %var% to access the changed value of var or 2) to call a subroutine to perform further processing using the changed values.
hence - easy fix:
SETLOCAL ENABLEDELAYEDEXPANSION
set /a x=0
:while1
if %x% leq 5 (
echo !x!
goto callfun
REM this following line appear to make no sense in winbatch
/dir:/Prod /user:admin /pass:anc /level:error >> C:\Logs\A.txt
set "file=C:\Logs\J_FINANCIALS_EVENING.log"
set /a cnt=0
for /f %%a in ('type "%file%"^|find "!Kitchen.Error.NoRepDefinied!" /i /c') do set /a cnt=%%a
if !cnt! NEQ 0 (
if !x! NEQ 5 (
DEL C:\Logs\abc.txt
)
set /a x=x+1
goto while1
)
echo "OUTSIDE LOOP"
echo The Status is !errorlevel!
call :check_file
exit /b !errorlevel!
)
endlocal
REM Note that this will fall-through to the process. Best add
GOTO :EOF
REM Here.
REM Colon must precede label
:callfun
CALL C:\Pentaho\pdi-ce-5.2.0.0-209\data-integration\kitchen.bat /rep:"Admin" /job:"XXXX"
REM Note that this would exit the subroutine by reaching (apparent) EOF. Best add
GOTO :EOF
REM Here - as a habit - it contributes to preventing fall-through failures
REM if you add a new subroutine and forget to include the newly-required goto :eof
Notes:
GOTO does not require a colon on the label except in the special case of :EOF which is defined to mean end of file
SET /a does not need quotes.
SET "stringname=stringvalue" is good syntax for string-assignments because the quotes cause any trailing spaces on the line to not be included in the value assigned.
any %var% which is varied within the loop should become !var! with delayedexpansion to access the run-time rather than the parse-time value.
(I've only tackled the delayed-expansion errors - other problems are flagged with REMs)
=symbols. Your first line does not set x to 0, but sets the variablexto the string ` 0` (note the spaces). Also, near the bottom you haveset /d- there is no/doption. You want/afor math.