Solved

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

Posted on 2009-07-06
7
6,765 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 68

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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now