1.

Solve : Do Loop??

Answer»

I am trying to perform a function that will send out an email and retry the function until it passes my condition. It has been a few years since I have used batch commands and I am in need of some help. Here is what I have so far:

:START

(I have other criteria here that will run what I need)


if %errorlevel% GTR 0 goto fail

:fail
C:\Email.bat [emailprotected] "Execution Failed" "The scheduled JOB failed to execute"

goto startand whats EXACTLY wrong with that ?You do not have a for loop which contains "DO" You have A GOTO loop. Goto start needs to be directly after the test condition. The order of test and and Goto start that you have allows :fail to execute regardless of the test condition.

Quote

:start

(I have other criteria here that will run what I need)


if %errorlevel% GTR 0 goto fail

:fail
c:\Email.bat [emailprotected] "Execution Failed" "The scheduled job failed to execute"

goto start

C:\>cat gostart.bat
Code: [Select]@echo off

:start

echo Enter errorleve

set /p errorlevel=



if %errorlevel% GTR 0 goto fail

goto start

:fail
REM c:\Email.bat [emailprotected]

echo "Execution Failed" "The scheduled job failed to execute"

goto start
C:\> gostart.bat
Output:

Enter errorleve
-10
Enter errorleve
0
Enter errorleve
66
"Execution Failed" "The scheduled job failed to execute"
Enter errorleve
2
"Execution Failed" "The scheduled job failed to execute"
Enter errorleve
-7
Enter errorleve


Discussion

No Comment Found