I am trying to find a way to exit the FOR loop if an error occurs. The following is the contents of the batch file.
@echo on set myfile=D:\sample.txt FOR /F "tokens=1,2 delims=," %%i in (%myfile%) do call :process "%%i" :process set recfile=%1% echo %recfile% echo "Step in Test1" echo %errorlevel% pause; exit /B 0 If %errorlevel% NEQ 0 goto :fail1 :fail1 echo "Step in fail1" pause; exit /B 9993 :EOF
Sample.txt has several entries. If any error occurs, I expect to exit the batch file and then check the full sample.txt file. for example according to the statement echo% recfile%. If I put the incorrect command ech% recfile%, which is the wrong command, then I expect it to go to the fail1 level and exit. He successfully coded the error code and switched to the fail1 level, however after this state he again checks the sample.txt file (next record). Is there a way if I can break / exit the FOR loop.
Please advice.
Thanks,
command-line cmd for-loop control-flow
source share