繁体   English   中英

批处理Windows 7:循环读取文本文件

[英]batch windows 7: loop to read a text file

我有一个像这样的文本文件:

info1子信息1

info2子信息2

info3子信息3

我必须使用这些信息在命令上执行循环。 我这样做:

for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
        set stack=%%a
        set orientation=%%b 
        command1 -i test -o test -option1 %stack% -option2 %orientation%
)

没用 选项始终相同。

确实,如果我这样做:

for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
set stack=%%a
set orientation=%%b   
echo %%a
echo %%b
echo %stack%
echo %orientation%
)

我有这个:

info1_lr

轴向的

info2_lr

矢状

info3_lr

info2_lr

矢状

info2_lr

矢状

info2_lr

矢状

那正常吗?

是。 绝对。

请使用搜索工具查找有关Stack Overflow delayed expansion信息。 推理和解决方案就在那里-这个问题已经被回答了数百次。

所以这是我的做法:

    for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
        setlocal enabledelayedexpansion
        set stack=%%a
        set orientation=%%b 
        echo %%a
        echo %%b
        echo !stack!
        echo !orientation!
        endlocal
)

在看了延迟的表情之后,它几乎对我有用。

除了我与“增加”变量的方式存在冲突之外:

set cmdIntensityNLM=%cmdIntensityNLM% -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz

我添加将其更改为:

set cmdIntensityNLM=!cmdIntensityNLM! -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM