disruptive
disruptive

Reputation: 5946

Scripting with Batch Files in DOS (NT) Windows Server 2008

I'm trying to go around the loop a fixed number of times, however I find I cannot seem to make this statement work with

REM @echo off
SET TotalCores=12
SET Sockets=2
SET SlaveNodes=4
SET /A mycores = %TotalCores% / %SlaveNodes%
FOR /L %i in (0,1,%SlaveNodes%) DO (call slavenode.bat  %i %mycores)

Why do I get the following issue?

SET /A mycores = 12 / 4
SlaveNodesi was unexpected at this time.

Is my formatting correct?

Upvotes: 1

Views: 339

Answers (2)

Ken White
Ken White

Reputation: 125757

Remove the spaces, and use double percent signs around your loop variable:

REM @echo off
SET TotalCores=12
SET Sockets=2
SET SlaveNodes=4
SET /A mycores=%TotalCores%/%SlaveNodes%
FOR /L %%i in (0,1,%SlaveNodes%) DO (call slavenode.bat  %%i %mycores%)

Upvotes: 3

Stephan
Stephan

Reputation: 56238

in batch files you must use double percentsigns for the for-variables:

FOR /L %%i in (0,1,%SlaveNodes%) DO (call slavenode.bat  %%i %mycores%)

(also you missed a % with your variable %mycores%)

Upvotes: 1

Related Questions