Does anyone know how to stop >nul being ignored when set in a variable, or is this not possible? I have a feeling that it’s one of those things that will only work once all variables have been expanded or something, but it can’t hurt to ask.
Example:
@echo off
:: Won't work
SET pause_5=ping localhost /n 6 >nul
%pause_5%
:: Will work
SET pause_5=ping localhost /n 6
%pause_5% >nul
exit
Put quotes around the argument:
Another option is to escape characters that will be interpreted by the shell:
But usually the quotes approach is a lot easier.
The way you wrote is essentially said »set
pause_5toping localhost /n 6and ignore the output of thesetcommand.«.