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.
Comments
- Anonymous
May 30, 2006
"choice" is another good option for pausing and controlling scripts. - Anonymous
May 30, 2006
The comment has been removed - Anonymous
May 30, 2006
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