30 May 2006

The NUL device is useful for supressing "Press any key to continue"

Long time scripters will, I'm sure, know this. Useful to mention as I was writing a script over the long weekend (it was memorial day here in the US yesterday - makes up for the many UK bank holidays I've missed over the past couple of months!) which needed a "pause" in it, but as this was for a non-tech savvy user, I wanted to indicate that they could also press Control-C to terminate the script there and then.

If you have test.cmd with the following contents:

@echo off
echo Example 1
echo Press any key to continue or Control-C to terminate script . . .
pause

the output won't be quite what you may want:

C:\>test
Example 1
Press any key to continue or Control-C to terminate script . . .
Press any key to continue . . .

To resolve this, simply add a > NUL onto the second pause:

@echo off
echo Example 2
echo Press any key to continue or Control-C to terminate script . . .
pause > NUL

to give the following output.

C:\>test
Example 2
Press any key to continue or Control-C to terminate script . . .

Cheers,
John.

 

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Geoff Nordli said:
"choice" is another good option for pausing and controlling scripts.
30 May 06 at 4:55 PM
# jhoward said:
Hi Geoff - good point, but (IIRC) I think choice is a resource kit utility from back in NT4 & 2000 days - ie not in the box by default? I'll have to go dig it out now but thanks for the reminder.
Cheers,
John.
30 May 06 at 5:04 PM
# Geoff Nordli said:
It is in the default install on WS03.

Another nice thing about choice is you can pause for X number of seconds before the script continues.

Have a great day!

Geoff
30 May 06 at 5:56 PM

Leave a Comment

Comment Policy: No HTML allowed. URIs and line breaks are converted automatically. Your e–mail address will not show up on any public page.

(required) 
(optional)
(required) 
Page view tracker