Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 用于批量发布中的循环_Windows_Batch File_For Loop - Fatal编程技术网

Windows 用于批量发布中的循环

Windows 用于批量发布中的循环,windows,batch-file,for-loop,Windows,Batch File,For Loop,我正试图将一个.sh脚本重写为一个.bat文件,以便在Windows虚拟机上测试它 我在FOR/F循环中遇到了一个问题,我无法使用我在循环中设置的变量,对此我非常沮丧。我已经四处寻找了一段时间,我已经启用了延迟扩展,没有运气。下面是一段代码: setlocal ENABLEDELAYEDEXPANSION FOR /F "eol=; tokens=1,2,3,4,5,6,7,8,9,10 delims=, " %%i in (%SOutPath%) do ( SET sKic1Length =

我正试图将一个.sh脚本重写为一个.bat文件,以便在Windows虚拟机上测试它

我在FOR/F循环中遇到了一个问题,我无法使用我在循环中设置的变量,对此我非常沮丧。我已经四处寻找了一段时间,我已经启用了延迟扩展,没有运气。下面是一段代码:

setlocal ENABLEDELAYEDEXPANSION
FOR /F "eol=; tokens=1,2,3,4,5,6,7,8,9,10 delims=, " %%i in (%SOutPath%) do (

SET sKic1Length = 20
SET sRAMTar = %%i
SET admCode = %%j
SET pin1Code = %%k
SET pin2Code = %%l
SET sKic1 = %%m
SET sKic1Length = %%n
SET sKid1 = %%o
SET sKid1Length = %%p
SET sRAMMSL=%%r

IF sKic1Length EQU 16 SET sKic1Length=11
IF sKic1Length EQU 32 SET sKic1Length=15
IF sKic1Length EQU 48 SET sKic1Length=19
::This echo outputs 'Echo is off' so variable is empty
@echo %sKic1Length%  

)
::Also returns same
ECHO %sKid1Length% 
下面是我在循环中读取的文件:

; ;, RAMTAR, ADM1, PIN1, PIN2, KIC1, KICLENGTH,KID1, KIDLENGTH, RAMMSL
000000, 17182320, 2387, 1116, 607038CA34A91FB1, 16, 607038CA34A91FB, 16, 0200
如果您有任何意见,我将不胜感激


谢谢

您必须使用!而不是在循环中启用DelayedExpansion时使用%

@echo off
setlocal ENABLEDELAYEDEXPANSION
for /f "eol=; tokens=1,2,3,4,5,6,7,8,9,10 delims=, " %%i in (%SOutPath%) do (
    set "sKic1Length=20"
    set "sRAMTar=%%i"
    set "admCode=%%j"
    set "pin1Code=%%k"
    set "pin2Code=%%l"
    set "sKic1=%%m"
    set "sKic1Length=%%n"
    set "sKid1=%%o"
    set "sKid1Length=%%p"
    set "sRAMMSL=%%r"
    if "!sKic1Length!" equ "16" set "sKic1Length=11"
    if "!sKic1Length!" equ "32" set "sKic1Length=15"
    if "!sKic1Length!" equ "48" set "sKic1Length=19"
    echo.!sKic1Length!
)
echo.%sKid1Length% 
endlocal
如果最后一个echo没有返回任何内容,那么我假设在最后一次迭代中%%p为空