Solved

Create a batch file that prompts user to press any key to exit

Posted on 2009-07-06
7
8,254 Views
Last Modified: 2012-05-07
I created a batch file however, I am want a command that will prompt the user to echo "Press any key to exit" and that once the key is entered it will exit.
0
Comment
Question by:gm5522
  • 4
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24787199
@echo off
rem the rest of your batch
pause
cls
exit

Is that what you mean?
Steve
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 24787206
If you want it to specifically say that:

@echo off
echo Press any key to exit
pause > nul
cls
exit
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 24787896
Normally, you would just add the pause command at the end of your batch. Nothing else is needed.
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 24788253
Agreed.... the pause is the important bit :-)
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24789974
All you need to add to your code are the following three lines:

   ECHO Press any key to exit
   PAUSE >NUL
   EXIT /B



You don't need these lines:

   @echo off
   cls

And be careful with the EXIT command because without the '/B' switch, EXIT will close down your DOS session too.
 
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24791803
toto you are just being pedantic now :-) I imagine the guy just wanted to know of pause... and in general at least someone running a batch file from a cmd window wouldn't need a press any key to exit...  the cls and exit is from older versions? of windows that would not close the window if something showed on the screen.... habit but not normally needed now as you say.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24834676
I don't suppose the asker knows how to split points between contributors....

So, he went with the CLS then?....
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question