I'm using WindowsXP Pro v5.1and am writing a BAT file to loop through a list of files (contained in a .txt file) and pass them (actually variables derived from them) to another program (ERDAS Imagine). What appears to be happening is that the FOR loop isn't utilizing the variables until the 2nd iteration after the variable is set. Since one variable is dependent on another, I have to run the program 3 times before the variables are correctly utilized. The 3rd time I run it the program works fine.
My original input list that I was using for testing had only two entries. To try to isolate what was going on, I made two separate FOR "loops", each with one entry. I've written in lots of echoes but still don't understand what's going on.
This is a subset of a larger program so let me know if you need more context. I'll include the relevant code below plus the echoes and results from the "set" command at the c:> prompt.
Here's the code:
Expand|Select|Wrap|Line Numbers
- ECHO OFF
- REM Testing var settings w/in imagine line
- REM and issuing import command for H3 and H1 header files
- set intar=C:\WorkSpace\LTC\MRLC_test\NZT
- echo ***** intar = %intar%
- set outtar=C:\WorkSpace\LTC\MRLC_test\NZT\tmp2
- echo ***** outtar = %outtar%
- set tlist=tarList1.txt
- echo ***** tlist = %tlist%
- echo.
- REM Create separate text files containing name of H1 and H3 header files
- dir /b %outtar%\*.H1 > %outtar%\hdr1Name.txt
- dir /b %outtar%\*.H3 > %outtar%\hdr3Name.txt
- REM Establish variable for text file containing H3 header file name
- set hlist3=%outtar%\hdr3Name.txt
- for /f %%h in (%hlist3%) do (
- set headr3=%%h
- set hbase3=%headr3:~0,18%
- set hex3=%headr3:~19,2%
- echo ***** Header3 file is %headr3%
- echo ***** Basename3 is %hbase3%
- echo ***** Extension3 is %hex3%
- echo.
- REM Open Imagine and call the import NLAPS script
- start "" "C:\Program Files\Leica Geosystems\IMAGINE and LPS 9.0\bin\ntx86\importndf.exe" -inputfilename "%outtar%/%headr3%" -outputfilename "C:/WorkSpace/LTC/MRLC_test/IMG/%hbase3%_%hex3%.img" -pixeltype u8
- )
- REM Establish variable for text file containing H1 header file name
- REM Originally this loop was incorporated in the loop above, but I separated
- REM them for diagnostic purposes.
- set hlist1=%outtar%\hdr1Name.txt
- for /f %%h in (%hlist1%) do (
- set headr1=%%h
- set hbase1=%headr1:~0,18%
- set hex1=%headr1:~19,2%
- echo ***** Header1 file is %headr1%
- echo ***** Basename1 is %hbase1%
- echo ***** Extension1 is %hex1%
- echo.
- REM Open Imagine and call the import NLAPS script
- start "" "C:\Program Files\Leica Geosystems\IMAGINE and LPS 9.0\bin\ntx86\importndf.exe" -inputfilename "%outtar%/%headr1%" -outputfilename "C:/WorkSpace/LTC/MRLC_test/IMG/%hbase1%_%hex1%.img" -pixeltype u8
- )
1ST RUN:
C:\>C:\WorkSpac e\LTC\MRLC_test \scripts-bats-docs\setvarInIm agine2.bat
C:\>ECHO OFF
***** intar = C:\WorkSpace\LT C\MRLC_test\NZT
***** outtar = C:\WorkSpace\LT C\MRLC_test\NZT \tmp2
***** IMG directory = C:\WorkSpace\LT C\MRLC_test\IMG
***** tlist = tarList1.txt
***** Header3 file is
***** Basename3 is
***** Extension3 is
***** Header1 file is
***** Basename1 is
***** Extension1 is
Set:
hbase1=~0,18
hbase3=~0,18
headr1=LE708301 4000019251.H1
headr3=LE708301 4000019251.H3
hex1=~19,2
hex3=~19,2
hlist1=C:\WorkS pace\LTC\MRLC_t est\NZT\tmp2\hd r1Name.txt
hlist3=C:\WorkS pace\LTC\MRLC_t est\NZT\tmp2\hd r3Name.txt
2ND RUN:
C:\>C:\WorkSpac e\LTC\MRLC_test \scripts-bats-docs\setvarInIm agine2.bat
C:\>ECHO OFF
***** intar = C:\WorkSpace\LT C\MRLC_test\NZT
***** outtar = C:\WorkSpace\LT C\MRLC_test\NZT \tmp2
***** IMG directory = C:\WorkSpace\LT C\MRLC_test\IMG
***** tlist = tarList1.txt
***** Header3 file is LE7083014000019 251.H3
***** Basename3 is ~0,18
***** Extension3 is ~19,2
***** Header1 file is LE7083014000019 251.H1
***** Basename1 is ~0,18
***** Extension1 is ~19,2
Set:
hbase1=LE708301 4000019251
hbase3=LE708301 4000019251
headr1=LE708301 4000019251.H1
headr3=LE708301 4000019251.H3
hex1=H1
hex3=H3
hlist1=C:\WorkS pace\LTC\MRLC_t est\NZT\tmp2\hd r1Name.txt
hlist3=C:\WorkS pace\LTC\MRLC_t est\NZT\tmp2\hd r3Name.txt
3rd RUN:
C:\>C:\WorkSpac e\LTC\MRLC_test \scripts-bats-docs\setvarInIm agine2.bat
C:\>ECHO OFF
***** intar = C:\WorkSpace\LT C\MRLC_test\NZT
***** outtar = C:\WorkSpace\LT C\MRLC_test\NZT \tmp2
***** IMG directory = C:\WorkSpace\LT C\MRLC_test\IMG
***** tlist = tarList1.txt
***** Header3 file is LE7083014000019 251.H3
***** Basename3 is LE7083014000019 251
***** Extension3 is H3
***** Header1 file is LE7083014000019 251.H1
***** Basename1 is LE7083014000019 251
***** Extension1 is H1
Thanks in advance,
Thom Curdts