The below piece of code keeps erroring out saying "8 was unexpected at this time." anb its poiting to this line : "if %var1:~1,8% NEQ Disabled". Any thoughts? Very strange thing is it works sometimes... I have seen it work many times and it has given error also many times... Its the same piece of code no change was done during both success and error.
@Echo off
if %date:~0,3% EQU Sat if %time:~0,2% EQU 10 (
schtasks /query | find /i "pdh_load_n_start_new_batches" > E:\PDH_Archive\SchStat.txt
for /f "tokens=2-3" %%# in ('type E:\PDH_Archive\SchStat.txt') do set var1= %%#
echo %var1%
if %var1:~1,8% NEQ Disabled (
echo Schedled task is not disabled. Will be disabling task now
)
)
Error in If logic
Moderator: DosItHelp
Re: Error in If logic
Hello venkimuck,
you got this error if var1 is empty/not exist.
The batch logic expands
to
hope it helps
jeb
you got this error if var1 is empty/not exist.
The batch logic expands
Code: Select all
if %var1:~1,8% NEQ Disabled (
to
Code: Select all
if ~1,8 NEQ Disabled (
hope it helps
jeb
Re: Error in If logic
1) The first if condition itself is not true, so it should not even go into the ( section under the if condition.
2) The file SchStat.txt does have value and when do the echo %var1%, it works fine (after removing the first if logic).
2) The file SchStat.txt does have value and when do the echo %var1%, it works fine (after removing the first if logic).
Re: Error in If logic
Hello venkimuck,
That's is the problem, it's not important if the first if condition is true.
The whole section is expanded, and the syntax must be correct.
Try
jeb
1) The first if condition itself is not true, so it should not even go into the ( section under the if condition.
That's is the problem, it's not important if the first if condition is true.
The whole section is expanded, and the syntax must be correct.
Try
Code: Select all
if "%var1:~1,8%" NEQ "Disabled" (
jeb
Re: Error in If logic
That worked... Thanks. But, given the nature of issue I have been facing, I would wait for more executions before I can confidently say this corrected the issue