Mar 13, 2012

NOP command in batch?

Though it seems silly, I decided to publish this very unnatural usage.

if "%1"=="/noreboot" (echo.>nul) else (call:reboot)

It is much easier just to write code that does not need NOPing:

if not "%1"=="/noreboot" (call:reboot)

You can either do it like thus:
set nop=set _%RANDOM%=%RANDOM%
if "%1"=="/noreboot" (%nop%) else (call:reboot)

There are many different recipes for NOP. You have to find a command that will (in human's way of thinking) do nothing (or, more simply, be neutral), and that will not affect the environment; keep the ERRORLEVEL variable untouched. Both of the examples I presented do not seem to touch ERRORLEVEL, at least in Windows 7.

No comments:

Post a Comment