50

I'm writing a Windows batch script. By default, the pause command will pause the script and display the text "Press any key to continue...".

How do I modify this text to display my own text to the user?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Hashim Aziz
  • 4,074
  • 5
  • 38
  • 68
  • 1
    Does this answer your question? [Changing Pause Message](https://stackoverflow.com/questions/17559738/changing-pause-message) – Codemaker2015 Sep 25 '20 at 14:14
  • @Codemaker Your supposed duplicate was asked a year after I asked this question. If anything that question is a duplicate of this one. – Hashim Aziz Mar 22 '22 at 15:57

11 Answers11

125

You could hide the text from the pause command by using this:

pause >nul

Then you could echo your own message to tell the user it has paused:

echo The batch file has paused

So the full script might look like this:

@echo off
echo Hello World!
echo The batch file has paused
pause >nul
Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Bali C
  • 30,582
  • 35
  • 123
  • 152
  • Not really what I was looking for, I was wondering whether there was a way of actually changing the output text of the Pause command, not just a workaround to it. – Hashim Aziz Feb 13 '12 at 12:13
  • 2
    No, AFAIK there is no way of changing that text. – Bali C Feb 13 '12 at 12:22
  • KK, exactly what I afraid I'd hear. Thanks for your help anyway, though, mate. :) – Hashim Aziz Feb 13 '12 at 17:33
  • 4
    Actually, I think this is the expected way of doing it. Since the PAUSE command doesn't accept arguments, you suppress its output, echoing your message just before PAUSE. I've seen batch files using this technique a lot of times. – LRMAAX Jan 26 '16 at 02:34
  • 6
    Thanks for the input, LRMAAX. Present me is kinda amused at past me's pedantry for a "proper" solution. A few years of experience with code later and my standards have dropped and I'll accept a "hacky" method graciously. Still, it's good to know this is the commonly-accepted way to do things anyway. – Hashim Aziz Oct 16 '16 at 22:17
  • @Hashim: I'm also amused, because I understand what you meant by that. Lack of time and looking for fast solutions makes workarounds and "hacks" a viable alternative in most cases. However, there's a downside to it, and I'm much more amused by the irony: this is a major reason why we have buggy software on the market, apart from human error. Experience apparently turns everyone into a "paper over the cracks" expert that goes for patching software again and again, instead of designing it properly right from the start. Me thinks the 2012 you was better than the current you, but that's just me... – Yin Cognyto Nov 25 '18 at 23:07
  • @YinCognyto I'm no brilliant coder, but I feel as with most things, there's a healthy balance to be struck in the middle; over-reliance on hacks and patches encourages unhealthy mindsets, ecosystems, and industries, but the kind of perfectionism that I had when young worships "rightness" for its own sake and is often debilitating and directly counter-productive. There's really something to be said for the bootstrapping/fake it 'till you make it method and building from that foundation incrementally, in contexts where you can afford to of course. – Hashim Aziz Nov 25 '18 at 23:12
  • 1
    @Hashim: I'm also an amateur coder, so don't worry. I fully agree with you, with one slight note: perfectionism is only counter-productive in terms of time spent, in this case, with coding. In terms of efficiency, it's the most productive. I guess it depends on the goals you look to achieve. To me, it's not about worshipping "rightness" for its own sake, it's about making things the best you can. Of course, in the end, none of this matters, as all software gets replaced sooner or later by newer (but not necessarily better) ones :) – Yin Cognyto Nov 25 '18 at 23:36
27

Here's a one-liner

  pause>nul|set/p =any key to exit ...

It's slightly shorter (one less 'nul') than Aacini's solution:

  set/p<nul =any key to exit ...&pause>nul

and, with the 'pause' first, I think that it's a little clearer what the intent is.

With both

  cursor stays on the same line  
  ANY key works, not just 'enter'  

Neither are as good, however, as the hypothetical

  pause/t any key to exit ...

It's hard to believe that 'pause' has survived 35 years without this ability ;-)

The solutions with 'echo' have the possibly undesirable trailing new-line,
but do provide for multiple lines of text:

  Pause>nul|(echo  All your bases &echo  are belong to us &echo Press any key to die...)

bv

bob vance
  • 271
  • 3
  • 2
  • 2
    Actually, I just realized that you can do multiple and AND have no trailing new-line: Pause>nul | (echo All your bases & echo are belong to us & set/p =Press any key to die...) – bob vance Sep 03 '15 at 13:06
9

"Not really what I was looking for, I was wondering whether there was a way of actually changing the output text of the Pause command, not just a workaround to it." – Hashim

Yes, you can! But you must be aware that PAUSE is an internal command of CMD.EXE program, so, to modify the message that PAUSE show, you must modify CMD.EXE file. To do that, you must use an editor that may modify binary files. I used XVI32 program via these steps:

1- Copy CMD.EXE file to a new folder created for this purpose: COPY %COMSPEC%
2- Edit the copy of CMD.EXE with XVI32.EXE program:
   2.1- Locate the message you want. Messages are stored in 16-bits elements with the high byte equal zero. To locate a message:
        2.1.1- In Search> Find> Text string> enter the message you want.
        2.1.2- Convert Text -> Hex
        2.1.3- Insert a zero after each letter-value
        2.1.4- Press Ok
   2.2- Modify the message for the new one. Modify existent letters only and keep zeros in place. Note that you can NOT extend any message.
   2.3- End the edition and save the modified file.

You may now run CMD.EXE to get the modified PAUSE message. I made a test of this procedure:

C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor
>pause
Press any key to continue . . .

C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor
>cmd
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\DOCUME~1\Antonio\MYDOCU~1\My Webs\XVI32 Hex File Editor
>pause
Oprime una tecla para seguir. .

Notes to everyone that read this answer:

NOTE 1: Please, don't post that comment saying that modifying CMD.EXE file must NEVER be done! I think the same. I just posted this answer so the OP realized what he really asked for...

NOTE 2: The reviewing of CMD.EXE file with a text editor, like Notepad, is very interesting. You may see all the internal commands, interesting details (like =ExitCode and =ExitCodeAscii variables), all the error messages, etc. For example, these are the internal commands:

C O L O R   T I T L E   C H D I R   C L S   C M D E X T V E R S I O N
D E F I N E D   C O P Y     P A T H     P R O M P T     P U S H D   P O P D
A S S O C   F T Y P E   D A T E     D E L   D I R   E C H O     E N D L O C A L
E R A S E   E R R O R L E V E L     E X I T     E X I S T   B R E A K   F O R
G O T O     I F         K E Y S     M K D I R   M D     N O T   P A U S E   R D
R E M       M O V E     R E N A M E     R E N   R M D I R   S E T   S E T L O C A L
S H I F T   S T A R T   T I M E     T Y P E     V E R I F Y   V E R   V O L   = , ; + / [ ]      "     : . \ 


                                         P A T H E X T   P A T H     P R O M P T

                                                           F O R / ?   I F / ?     R E M / ?



            % s               % s
       % s 

         / A     / P     : E O F         
       f d p n x s a t z   D O
/ L     / D     / F     / R         I N     E L S E     ( % s )   % s       % s   % s % s
     % c % c     % s   % s                 & ( ) [ ] { } ^ = ; ! % ' + , ` ~               
Aacini
  • 65,180
  • 12
  • 72
  • 108
  • 3
    Yeah, I'm not even going to risk editing CMD.exe, lol. I was just hoping it would be a parameter or something of `PAUSE` which allowed to do so. Besides, even if I did manage to modify the CMD.exe successfully, I'd still have to apply the same modification on all the machines I intend to use my script on, wouldn't I? Which would be next to impossible and completely impractical. Thanks anyway Aacini. – Hashim Aziz Feb 14 '12 at 12:30
  • 4
    I still don't understand why you want not an equivalent solution, like this one: `SET /P =Any text you want < NUL` followed by `PAUSE > NUL`. – Aacini Feb 15 '12 at 01:36
5

There is no way to change the text of the pause command. However you might want to look at the choice command. You can change the text it prints. The only downside is that you need to provide a list of acceptable characters.

Michael
  • 8,920
  • 3
  • 38
  • 56
  • Just checked the `choice` command out, Michael. A) I'm not really understanding how it would help me accomplish what I want to in this case, unless you're suggesting I use `choice` instead of the `pause` command? B) It doesn't really matter anyway as I am running Windows XP, and the choice command isn't supported for it unless I download an extra resource kit apparently. See here: http://www.robvanderwoude.com/choice.php. If I did download the extra resource kit to use it, I would have to do the same on all computers I'm intending to use my script on, wouldn't I? – Hashim Aziz Feb 13 '12 at 22:57
3

Already many solutions. Another variation that makes some sense:

echo Hit any key to continue...&pause>nul
Basalt
  • 31
  • 2
2

Another dirty solution would be something like this,

SET /P =Press enter to return to the menu . . . 
GOTO :menu

The benefit of this is that the cursor stays on the same line as the message, just like with the PAUSE command.

The downside is that it only listens to the enter key.

Trevi Awater
  • 2,387
  • 2
  • 31
  • 53
2

Here’s another trick

Pause. >nul | echo.  Press something to continue
Panikosagros
  • 97
  • 1
  • 6
1

Starting from Windows 2000 (so, not XP) you can use the choice command which is far more powerful than either pause or set /p.

Besides being able to specify your own prompt text, you can also require the user to type a specific key, and only that key, instead of being limited to, and requiring, [Enter] to be pressed.

Also, you can prompt the user to press a number of different keys and take action based on which key was pressed.

Type choice /? for help, or read more about it here: Wikipedia: choice (command)

Mike Nakis
  • 56,297
  • 11
  • 110
  • 142
1

Since I dont see it suggested and every dog on the internet has had a go, but me.

This may not have worked under XP, as required by OP, but is valid for any newer system like my current Win7 :-)

Dirty version (no message) |keys ON does nothing, but block the press any key ...

timeout -1|Keys ON

can be used for message after @timeout -1|Keys ON&echo I'm back

This one will pause and show a response until accepted then return to prompt/next cmd line

@timeout -1|Echo Hello Padawan %userprofile:~9%, Press a key, you can! 
:on any keys
@echo Welcome to the dark side

enter image description here

or boost that to the nth

@color 04&echo/&timeout -1|set /p="Hello %userprofile:~9%, you may press a key to proceed..."&color&echo  Continuing with process...

enter image description here

K J
  • 8,045
  • 3
  • 14
  • 36
0

You could do it like this!

@echo off
echo Hello World!
echo:
echo Press 1 to continue
set /p letter=

if %letter% == 1 goto a ;or instead of goto you could write start and the file or website you want to start
pause >nul

:a
cls 
echo BYE NOW!
pause >nul
Super461
  • 1
  • 2
0
pause|echo text you want displayed

Picture of cmd pause custom text

Paul Roub
  • 36,322
  • 27
  • 84
  • 93