Reputation: 1076
I am trying to learn Batch.
I wrote a simple code with two labels.
This is the code:
@echo off
title intro
color 1f
::############################
::label
:one
cls
echo hello
echo. please enter your First name
echo.
:: fname is a variable (type p - string) that will content the user input. the input will be insert after <<
set /p fname= ">>"
echo.
echo. please enter your Last name
set /p lname=">>"
echo.
echo hello %fname% %lname%!
pause>nul
goto two
::############################
:two
cls
echo. welcome to page two
After the command line prints "hello ", it waits for the user response. if the user hits enter, instead of continuing to label "two", the command line closes.
Why?
Thanks.
Upvotes: 0
Views: 1427
Reputation: 79982
You don't say whether you are executing that batch from the prompt or from a shortcut"
After showing hello names entered the batch stops at the pause
, and waits for an Enter. The >nul
suppresses the prompt Press any key to continue . . .
batch will then continue to :two
(the goto
is redundant) but if you executed the routine from a "shortcut" the batch window will appear to close immediately as reaching end-of-file terminates the routine.
Upvotes: 1
Reputation: 703
Thats because it exits when the script comes to and end and has nothing more to do.
Add for example a pause
at the very end of your script
Like this
echo. welcome to page two
pause
Then all you want on "page two" will be between your welcome to page two
and pause
Upvotes: 1