Showing posts with label batch. Show all posts
Showing posts with label batch. Show all posts

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

Wednesday, April 28, 2010

[Batch File] Rediscovering CMD.EXE batch scripts

Insanity must be setting in; I’ve been trying to solve RosettaCode tasks with Windows CMD.EXE batch scripts. For example, their A+B task:

A+B - in programming contests, classic problem, which is given so contestants can gain familiarity with online judging system being used.

A+B is one of few problems on contests, which traditionally lacks fabula.

Problem statement Given 2 integer numbers, A and B. One needs to find their sum.

Input data
Two integer numbers are written in the input stream, separated by space.
(-1000 \le A,B \le +1000)
Output data
The required output is one integer: the sum of A and B.
Example:

Input Output

2 2 4

3 2 5

These are what I posted as solutions:

Prompts version

::aplusb.cmd
@echo off
setlocal
set /p a="A: "
set /p b="B: "
set /a c=a+b
echo %c%
endlocal

All on the commandline version

::aplusb.cmd
@echo off
setlocal
set a=%1
set b=%2
set /a c=a+b
echo %c%
endlocal

Formula on the command line version

::aplusb.cmd
@echo off
setlocal
set /a c=%~1
echo %c%
endlocal

Example of 'Formula on the command line version'

>aplusb 123+456
579
>aplusb "1+999"
1000

Parse the input stream version (thanks to Tom Lavedas on alt.msdos.batch.nt)

::aplusb.cmd
@echo off
setlocal
set /p a="Input stream: "
call :add %a%
echo %res%
endlocal
goto :eof

:add
set /a res=res+%1
shift
if "%1" neq "" goto :add

Example of 'parse the input stream version'

>aplusb
Input stream: 1234 5678
6912
>aplusb
Input stream: 123 234 345 456 567 678 789 890
4082

Batch files are a bit arcane, it’s true, but the extensions added post Windows 2000 make it a lot more entertaining.

Monday, November 26, 2007

[Ada (GNAT/GCC)] Better build automation

Just after I notified comp.lang.ada of my posting re GNAT/GPL, Martin Krischik wrote suggesting I use a .gpr file and gnat make rather than a direct reference to gcc.

After reading a
friendly manual, I came up with the following .grp file and a batch file to control it.

I have stayed with the batch file, simply because I can't yet see how to have a multiple-program linkage (gnatlink, dlltool and gnatlink a second time).

First, build.gpr



And then, build.bat. Note the call to
UPX, which compresses the release version of the .DLL. Note also that the debug and release subdirectories must already exist (though it wouldn't have been difficult to check-for-and-create-if-missing.)



Trust that's helpful.

© Copyright Bruce M. Axtens, 2007