I have a text file like that:
info1 subinfo1
info2 subinfo2
info3 subinfo3
I have to perform a loop on command using these infos. I do it like that:
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%
)
It doesn't work. the option are always the same.
and Indeed if I do:
for /F "tokens=1,2" %%a in (%cd%\%SCANS%) do (
set stack=%%a
set orientation=%%b
echo %%a
echo %%b
echo %stack%
echo %orientation%
)
I have this:
info1_lr
axial
info2_lr
sagittal
info3_lr
coronal
info2_lr
sagittal
info2_lr
sagittal
info2_lr
sagittal
Is that normal ?
Yes. Absolutely.
Please use the search facility to find out about delayed expansion
on Stack Overflow. The reasoning and solution will be there - it's a question that's been answered hundreds of times.
so here is how I did:
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
)
after looking at delayed expression and it almost works for me.
except that I have a conflict with a way to "increment" a variable:
set cmdIntensityNLM=%cmdIntensityNLM% -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz
I add to change it to:
set cmdIntensityNLM=!cmdIntensityNLM! -i %RESULTS%/!stack!_blabla_%ITER%.nii.gz -o %RESULTS%/!stack!_blabla_%ITER%.nii.gz
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.