Friday, June 29, 2012

[Batch] Running on Low

Running on LOW priority (or any other priority class) can be done from the command line with the START command, e.g.
START /LOW SomeBatch.cmd
Alternatively, one can embed the START command with the priority class modifier within the batch file itself, viz
@echo off
 setlocal enableextensions
 if %1@==@ (
  start /low %0 running
 goto :eof
 )
 echo This instance is running at LOW priority class
 pause
 exit
One could even make the priority class one of the parameters to the call, e.g.
@echo off
 setlocal enableextensions
 set PC=%1
 if %PC%@==@ (
 echo Please specify priority class as first argument.
 goto :eof
 ) 
 if %2@==@ (
 start /%PC% %0 %1 running
 goto :eof
 )
 echo Supposedly running %PC%
 pause
 exit
The trick is to check, in the first instance, for something in the %1 slot, and in the second, in the %2 slot, with the assumption that 'nothing' means %0 is running for the first time. Note also, that no checking of meaningful priority classes is done. That's left as an exercise for the reader.
© Copyright Bruce M. Axtens, 2012

No comments: