if statement - Go Back to Start If no input is entered (Bat File) -


ok first have i'm sorry poor english :) problem

i'm trying create script file multiple choices , ran problem. if don't enter input (just press enter) file displays error , shuts down. question whether there command force file go start in case no input entered?

this relevant part of script

:input @echo off cls echo   ############################################# echo   #                                           # echo   #  1 - make system folder or file         # echo   #  2 - restore folder or file               # echo   #  3 - exit                                 # echo   #                                           # echo   #############################################  set /p o=set choice , press enter: echo loading ......... ( if %o%==1 goto hide if %o%==2 goto show if %o%==3 goto exit if %o%=="" goto input )  else (     goto input ) 

as can see tried use "else" works partially. if enter variable not part of list given (in case 1, 2, 3) file gose beginning, , if send non input request afterword file keep working properly. problem specific, when first input non input problem occurs. in other situation script works fine

thank , again i'm sorry poor english :)

  1. always reset variable before input. when user presses enter variable doesn't reset automatically.

    :: delete variable %o% set "o=" set /p "o=set choice , press enter: " 
  2. always take variables in quotes (in if)

    if "%o%"=="1" goto hide if "%o%"=="2" goto show if "%o%"=="3" goto exit 
  3. goto label never returns (exception - goto :label in crazy cases). in case can write:

    if "%o%"=="1" goto hide if "%o%"=="2" goto show if "%o%"=="3" goto exit  goto input 
  4. add after each 'procedure' command exit /b prevent crazy parsing after code changing. warning: goto command doesn't work void in c++, command exit /b stop script. if using call :label command exit /b stop code under :label.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -