|
Answer» Hi,
Following is my script:
@echo off setlocal
IF NOT EXIST SAVE.FLG ( set /P Choice="Press Y to give SAVE.FLG = " echo %Choice% if /I "%Choice%"=="Y" ( echo Please give the Text to be entered in SAVE.FLG set /P Text="Text = " If "%Text%"=="" ( echo You haven't entered Text echo %Text% goto End ) echo %Text% > SAVE.FLG )) else ( echo SAVE.FLG already exists ) )
endlocal :End
The problem is that it isn't reading the VARIABLE "Choice" and "Text". It simply asks for the values, and then doesn't registers them. The echo variable beneath them simply prints "echo off"
Please help.I am also posting the output:
Press Y to give SAVE.FLG = Y < I am entering Y here > ECHO is off.
Since its not reading the Choice Variable, its not asking for the Text variable either.One more update:
If i take the input of 2 variables before the first IF loop, then everything works fine.i donno about your case but this works on mine, at least , it shows me the "Please give the Text to be entered in SAVE.FLG" step
@echo off IF NOT EXIST SAVE.FLG ( set /p result=Press Y to give SAVE.FLG echo choice is %result% @echo on if /I "%result%"=="Y" ( echo Please give the Text to be entered in SAVE.FLG @set /P Text="Text = " @If '%Text%'=='' ( @echo You haven't entered Text @echo %Text% @goto End ) echo %Text% > SAVE.FLG ) ) else ( echo SAVE.FLG already exists ) )
:EndAre the variable getting echoed:
Try this by OPENING a new command prompt, as sometimes it gets stored outside and then.Are you sure: :-?
I just copied your script and it doesn't reach the line "Please give the Text to be entered in SAVE.FLG"
Neither does it echo the variable. Please try with a new command prompt.
Thanks
You may WANT to consider KEEPING your batch CODE as simple as possible:
Code: [Select]@echo off setlocal if exist save.flg ( echo save.flg already exist goto end ) set /p result=Press Y to give SAVE.FLG echo Choice is %result% if /i not %result%==Y goto end echo Please give the Text to be entered in SAVE.FLG set /P Text="Text = " if "%Text%"=="" ( echo You haven't entered Text goto End ) else ( echo %Text% > SAVE.FLG ) :end endlocal
Hope this helps. 8-)Thanks
This one works, any guesses why the above ones were not working.
Let me try to rethink the structure of my script.
|