I am having loop issues in my batch file. When using the set command, I give the user two choices. The first option works fine however the second option is ignored unless a loop function is done to re-ask the question. Then it accepts the input for the second option.
:WithAccess
cls
If not exist "C:\Program Files (x86)\Microsoft Office\Office15\Winword.exe" (
goto UninstallViewers
:WithAccess2
echo Installing MS Office 2013 x32 With Access...
start /wait "" "MS Office 2013 x32 Installers\MSOfficeWithAccess"
echo Installation Complete.
) Else (
echo Microsoft Office 2013 might already be installed.
set /p op4=Do you want to run installer anyway? [Y/N]:
If "%op4%"=="y" goto WithAccess2
If "%op4%"=="n" goto end
echo That's not a valid option.
goto WithAccess
)
So, in the "Else" part of this if statement, when the user chooses option 2 or "n" it will ignore this and move onto whatever code is after it. In this case it loops back to the beginning of this code segment. However after the loop, it now accept the user input and correctly jumps to the "end" label.
After playing around I found that removing the labels surrounding this segment fixes it, but that makes it so if the user makes an error, it wont loop back and re-ask the question. Originally my "Else" statement looked like this:
Else (
echo Microsoft Office 2013 might already be installed.
:Loop2
set /p op4=Do you want to run installer anyway? [Y/N]:
If "%op4%"=="y" goto WithAccess2
If "%op4%"=="n" goto end
echo That's not a valid option.
goto Loop2
)
So that it would ideally loop the same question but obviously the same issue occurred. I've tried searching around for the answer but its hard to search for such a specific coding issue. Any help would be appreciated.