Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
wingnut0420
- Posts: 5
- Joined: 19 Apr 2013 07:38
#1
Post
by wingnut0420 » 19 Apr 2013 14:08
Try this on for size. First run through will not set the variable "wtf"
have it pausing so you can see example
but second run will set it
Also, try answering y to the first prompt, then just hitting enter at the next
seems like the first prompt will set it but not able to read it
WUT?????
Code: Select all
set prdico=Y
set WTF=
:WIconprompt
IF "%prdico%"=="Y" (
Echo ==================================================
Echo Prod icon detected, would you like to install
Echo the "Schoolhouse" Icon for Non Production [Y/N]
Echo ==================================================
SET /P WTF=Please select [Y/N]
IF "%WTF%"=="Y" (
Set Return=END
GOTO WIiconNP
)
IF "%WTF%"=="y" (
Set Return=End
GOTO WIiconNP
)
IF "%WTF%"=="N" GOTO END
IF "%WTF%"=="n" GOTO END
echo WTF= %WTF%
echo oops
echo ===============================
echo Please select [Y/N]
echo ===============================
pause
GOTO WIconprompt
)
:WIiconNP
echo works
pause
:End
echo end
pause
-
wingnut0420
- Posts: 5
- Joined: 19 Apr 2013 07:38
#2
Post
by wingnut0420 » 19 Apr 2013 14:15
Better example, cleaned up a bit
Try pressing Y to first prompt....then hitting enter second time
Code: Select all
@echo off
set prdico=Y
set WTF=
:WIconprompt
IF "%prdico%"=="Y" (
Echo ==================================================
Echo Prod icon detected, would you like to install
Echo the "Schoolhouse" Icon for Non Production [Y/N]
Echo ==================================================
SET /P WTF=Please select [Y/N]
IF "%WTF%"=="Y" (
Set Return=END
GOTO WIiconNP
)
IF "%WTF%"=="y" (
Set Return=End
GOTO WIiconNP
)
IF "%WTF%"=="N" GOTO END
IF "%WTF%"=="n" GOTO END
echo WTF= %WTF%
echo oops
echo ===============================
echo Please select [Y/N]
echo ===============================
pause
GOTO WIconprompt
)
GOTO end
:WIiconNP
echo works
pause
exit
:End
echo end
pause
-
Endoro
- Posts: 244
- Joined: 27 Mar 2013 01:29
- Location: Bozen
#3
Post
by Endoro » 19 Apr 2013 15:35
Normal %variables% can't change their value inside a code block.
You should use delayed expansion and !variables!.
-
Ranguna173
- Posts: 104
- Joined: 28 Jul 2011 17:32
#4
Post
by Ranguna173 » 20 Apr 2013 04:59
Code: Select all
@echo off &setlocal enableDelayedExpansion
set prdico=Y
:WIconprompt
cls
IF /i "%prdico%" neq "Y" goto end
Echo ==================================================
Echo Prod icon detected, would you like to install
Echo the "Schoolhouse" Icon for Non Production [Y/N]
Echo ==================================================
SET /P WTF=Please select [Y/N]:
if not defined WTF goto wiconprompt
IF /i "%WTF%"=="Y" (
Set Return=END
GOTO WIiconNP
)
IF /i "%WTF%"=="N" GOTO END
cls
echo WTF= %WTF%
echo oops
echo ===============================
echo Please select [Y/N]
echo ===============================
pause
GOTO WIconprompt
:WIiconNP
echo works
pause
exit
:End
echo end
pause
Try this one.
By doing this the batch will skip the code instead of adding it inside the if, this way you can change variables.
I added "/i" after the "if" it'll set the command to insensitive:
%var% can be either "Y" or "y"
I also added "cls" to make it a little more clean.