Solved

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

Posted on 2009-07-06
7
8,743 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

Title # Comments Views Activity
CMD shell elevation.js 4 72
Internet Connection Util 8 111
how to  skip files that were already there? 3 48
access denied when running native SQL tool: SQLIOSIM 2 58
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…

749 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