To make your script pause simply use the PAUSE
command.
PAUSE
This will display the text Press any key to continue . . .
, then add a newline on user input.
Let's say we want to create a "Hello World" program and after we click something on our keyboard, we want it to exit the program with the EXIT
command.
echo Hello World
pause
exit
Here it uses the ECHO
command to say "Hello World". Then we use the PAUSE
command which displays Press any key to continue . . .
and then we use the EXIT
command to terminate the current BATCH script.
When it's pausing it will display:
Press any key to continue . . .
Hide the "Press any key to continue... prompt
To hide the message we redirect the output to a special device called nul
. This isn't actually a real device, but whatever we send to it is thrown away.
pause > nul