locked file after "text > ..."

#1
Can someone explain me what I'm doing wrong?
After the 1st run of the script the file "C:\temp\ifitems.txt" is locked.
Probably I'm blind and it's an obvious thing.
Code:
>ver
TCC  14.03.52 x64   Windows 2008R2 [Version 6.1.7601]
>plugin
TCC: No plugins loaded
 
>..\array-demo.btm
setlocal
on        break cancel
on        errormsg pause error in line %_batchline
gosub        ifitems
text > "C:\temp\ifitems.txt"
setarray /r "C:\temp\ifitems.txt" ifitems
return
echo        8 elements
       8 elements
do        n = 0 to %@dec[%@arrayinfo[ifitems,5]]
echo 0: description
0: description
echo 1: duplex
1: duplex
echo 2: speed
2: speed
echo 3: shutdown
3: shutdown
echo 4: spanning-tree guard root
4: spanning-tree guard root
echo 5: spanning-tree portfast
5: spanning-tree portfast
echo 6: spanning-tree portfast edge
6: spanning-tree portfast edge
echo 7: spanning-tree bpduguard enable
7: spanning-tree bpduguard enable
pause
Press any key when ready...
endlocal
quit

>..\array-demo.btm
setlocal
on        break cancel
on        errormsg pause error in line %_batchline
gosub        ifitems
text > "C:\temp\ifitems.txt"
TCC: (Sys) \\osram.de\Net-BER\DV\TFTP\array-demo.btm [19]  The process cannot access the file because it is being used by another process.
 "C:\temp\ifitems.txt"
pause error in line 19
error in line 19^C
cancel

>handle -p tcc

Handle v3.46
Copyright (C) 1997-2011 Mark Russinovich
Sysinternals - www.sysinternals.com

------------------------------------------------------------------------------
tcc.exe pid: 2032 OSRAM_DE\Admin123456
    C: File  (RW-)   \Device\Mup\app-ber-netmon.ber.osram.de\tftp-root\20121207
   1C: File  (RW-)   C:\Windows\winsxs\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.17514_none_fa396087175ac9ac
  160: Section       \Sessions\3\BaseNamedObjects\TakeCommand_7f0
  164: Section       \Sessions\3\BaseNamedObjects\SharememUAliasAdmin123456
  168: Section       \Sessions\3\BaseNamedObjects\SharememUFunctionAdmin123456
  16C: Section       \Sessions\3\BaseNamedObjects\SharememUHistoryAdmin123456
  170: Section       \Sessions\3\BaseNamedObjects\SharememUDirHistoryAdmin123456
  198: Section       \BaseNamedObjects\__ComCatalogCache__
  1A4: Section       \BaseNamedObjects\__ComCatalogCache__
  1AC: File  (R--)   C:\Windows\Registration\R00000000001e.clb
  1B4: File  (RW-)   C:\Windows\winsxs\amd64_microsoft.windows.gdiplus_6595b64144ccf1df_1.1.7601.17825_none_2b253c8271ec7765
  1C4: File  (R--)   C:\Temp\ifitems.txt
This is my "array-demo.btm":
Code:
@echo   on
setlocal
on      break cancel
on      errormsg pause error in line %_batchline

gosub   ifitems
echo    %@arrayinfo[ifitems,5] elements
do      n = 0 to %@dec[%@arrayinfo[ifitems,5]]
        echo %n: %ifitems[%n]
enddo
pause

:end
endlocal
quit

:ifitems

text > "%temp\ifitems.txt"
description
duplex
speed
shutdown
spanning-tree guard root
spanning-tree portfast
spanning-tree portfast edge
spanning-tree bpduguard enable
endtext

setarray /r "%temp\ifitems.txt" ifitems

return
 
#3
Thank you Steve, but no enhancement.

@echo on
setlocal
on break cancel
on errormsg pause error in line %_batchline
setdos /n0

gosub ifitems
echo %@arrayinfo[ifitems,5] elements
do n = 0 to %@dec[%@arrayinfo[ifitems,5]]
echo %n: %ifitems[%n]
enddo
pause
unsetarray ifitems
echo %@arrayinfo[ifitems,5] elements
del "%temp\ifitems.txt"

:end
endlocal
quit

:ifitems

text > "%temp\ifitems.txt"
description
duplex
speed
shutdown
spanning-tree guard root
spanning-tree portfast
spanning-tree portfast edge
spanning-tree bpduguard enable
endtext

setarray /r "%temp\ifitems.txt" ifitems

return


Code:
setlocal
on      break cancel
on      errormsg pause error in line %_batchline
setdos  /n0
gosub    ifitems
text > "C:\temp\ifitems.txt"
setarray /r "C:\temp\ifitems.txt" ifitems
return
echo    8 elements
  8 elements
do      n = 0 to %@dec[%@arrayinfo[ifitems,5]]
echo 0: description
0: description
echo 1: duplex
1: duplex
echo 2: speed
2: speed
echo 3: shutdown
3: shutdown
echo 4: spanning-tree guard root
4: spanning-tree guard root
echo 5: spanning-tree portfast
5: spanning-tree portfast
echo 6: spanning-tree portfast edge
6: spanning-tree portfast edge
echo 7: spanning-tree bpduguard enable
7: spanning-tree bpduguard enable
pause
Press any key when ready...
unsetarray ifitems
echo    -1 elements
  -1 elements
del    "C:\temp\ifitems.txt"
Deleting C:\temp\ifitems.txt
TCC: (Sys) \\osram.de\Net-BER\DV\TFTP\array-demo.btm [15]  The process cannot access the file because it is being used by another process.
"C:\temp\ifitems.txt"
pause error in line 15
error in line 15
endlocal
quit
 
#4
I now verify identical behavior on WinXP SP3 (32b) with the 32b version of the same TCC build: 14.03.52. My suspicion is that SETARRAY /R does not close the file. Tried running under V13, but the /r option of SETARRAY is new to V14. However, it did create the file, and it could be deleted, which supports my suspicion of SETARRAY /R.