【问题标题】:Scripting with Batch Files in DOS (NT) Windows Server 2008在 DOS (NT) Windows Server 2008 中使用批处理文件编写脚本
【发布时间】:2013-10-16 16:47:21
【问题描述】:

我正在尝试循环执行固定次数,但我发现我似乎无法使用此语句

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)

为什么会出现以下问题?

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

我的格式正确吗?

【问题讨论】:

    标签: file batch-file scripting dos


    【解决方案1】:

    删除空格,并在循环变量周围使用双百分号:

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

    【讨论】:

    • set /a 的空格没有问题。 (虽然简单的set 会带来麻烦...)
    • set /a 不喜欢 var 名称和赋值 (=) 之间的空格。它只是导致了一个稍微不同的错误。
    • 另一个问题是现在如何传递核心数量。我在使用 slavenode.bat 文件中的 %2 访问内核数时遇到问题。
    • @KenWhite:我对 Win7 中的空格没有问题。 @user673600:这段代码中有一个%missing。看我的回答。
    • @Stephen:你是对的;我错过了一个复制/粘贴。固定。
    【解决方案2】:

    在批处理文件中,您必须对 for 变量使用双百分号:

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

    (您也错过了带有变量 %mycores% 的 %

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-22
      • 2014-07-21
      • 1970-01-01
      • 2010-09-13
      • 2013-01-07
      • 1970-01-01
      • 2013-01-22
      • 1970-01-01
      相关资源
      最近更新 更多