1

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?

2 Answers 2

3

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%)
Sign up to request clarification or add additional context in comments.

5 Comments

set /a has no problems with the spaces. (while a simple set will make trouble...)
set /a didn't like the spaces either between the var names and assignment (=). It just caused a slightly different error.
One of the other issues is now how to pass in the number of cores. I'm having trouble with the accessing the number of cores using %2 in my slavenode.bat file.
@KenWhite: I have no problem with the spaces in Win7. @user673600: there is a %missing in this code. See my answer.
@Stephen: You're right; I missed one with the copy/paste. Fixed.
1

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%)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.