What limit have I run into?

May 20, 2008
11,437
99
Syracuse, NY, USA
This BTM will copy a file.

Code:
setlocal
set nReadSize=2045
set nReads=%@eval[ceil(%@filesize[%1]/%nReadSize)]
set hIn=%@fileopen[%1,r,b]
set hOut=%@fileopen[%2,w,b]
on break goto close
do i=1 to %nReads
    set junk=%@filewriteb[%hOut,-1,%@filereadb[%hIn,%nReadSize,x]]
enddo
:close
set junk=%@fileclose[%hOut]
set junk=%@fileclose[%hIn]

If I change nReadSize to 2046 (and use a file bigger than that) it fails as follows.

The DO loop never terminates. And, each time through the DO loop what's written to the output file is: the first 2046 bytes of the input file followed by 0x40 0xFF.

What's happening? [It's a counted DO loop so I can't understand how it could fail to terminate regardless of whether the file read/writes are correct.]
 
May 20, 2008
11,437
99
Syracuse, NY, USA
The do loop would terminate correctly but it seemed to go on forever because @FILEWRITEB went haywire. Maybe this will shed some light on what's happening. Here is a single manual read/write of 2045 bytes; all seems well. The DATA variable has the form "0xHH 0xHH ..." so the lengths are correct.

Code:
v:\> echo %@repeat[x,2050] > in.txt

v:\> set hin=%@fileopen[in.txt,r,b]

v:\> set hout=%@fileopen[out.txt,w,b]

v:\> set data=%@filereadb[%hin,2045,x]

v:\> echo %@len[%data]
10224

v:\> echo %@filewriteb[%hout,-1,%data]
2045

v:\> echo %@fileclose[%hin] %@fileclose[%hout]
0 0

v:\> dir /k /m in.txt;out.txt
2020-10-15  15:18           2,052  in.txt
2020-10-15  15:20           2,045  out.txt

Here's the same for 2046 bytes. It takes a while because the one @FILEWRITEB actually writes 67,580 bytes!

Code:
v:\> set hin=%@fileopen[in.txt,r,b]

v:\> set hout=%@fileopen[out.txt,w,b]

v:\> set data=%@filereadb[%hin,2046,x]

v:\> echo %@len[%data]
10229

v:\> echo %@filewriteb[%hout,-1,%data]
67580

v:\> echo %@fileclose[%hin] %@fileclose[%hout]
0 0

v:\> dir /k /m in.txt;out.txt
2020-10-15  15:15           2,052  in.txt
2020-10-15  15:16          67,580  out.txt
 
Aug 9, 2009
233
1
It all works fine if you specify "1" data=%@filereadb[%hin,1,x] or am i missing something
 
May 20, 2008
11,437
99
Syracuse, NY, USA
On second thought ... I don't understand. @FILEREADB gives a space-separated string of ASCII character numbers. And that string goes directly to @FILEWRITEB (as third parameter). Are the spaces then considered parameter separators?
 
May 20, 2008
11,437
99
Syracuse, NY, USA
Yes, the spaces are parameter separators.
2K parameters seems to be a problem only for @FILEWRITEB. I haven't tried too hard but I can't find another variable function which chokes on a string with 2048 spaces in it. Below, the variable zz contains 0 1 2 3 4 ... 2047 2048. Can't @FILEWRITEB simply be made to behave better?

Code:
v:\> set zz=0

v:\> do i=1 to 2048 (set zz=%zz %i)

v:\> echo %@len[%zz]
9134

v:\> echo %@words[%zz]
2049

v:\> echo %@right[10,%zz]
 2047 2048

v:\> echo %@instr[9,-10,%zz]
 2047 2048

v:\> echo %@word[2047-,%zz]
2047 2048

v:\> echo %@regex[2047,%zz]
1

v:\> echo %@wild[%zz,*2047*]
1

v:\> echo %@tspace[%zz]
2048
 
Similar threads
Thread starter Title Forum Replies Date
D What is the limit on the compound statement length within ( ) of a FOR-loop? Support 5
L managing registered computer names: limit = 3 Support 1
T Bogus license limit Support 4
vefatica Is there an 8MB limit somewhere? Support 25
S BDEBUGER: watch list limit? Support 4
S CLIP file size limit Support 1
hrensink Path length limit Support 9
B 56-line Window Limit? Support 2
S SENDMAIL attachment size limit Support 1
S How to? Runs start /w in invisible mode OR run program after exit of another one Support 3
Jay Sage Command Will Not Run Using Short Name of Path Support 5
Peter Murschall BDEBUGGER "Run to Cursor" - where is it ? Support 1
Jay Sage Problem with Context Menu Copy+Paste+Run Key Assignment Support 7
D What does the file "..\Everything\Run history.csv" store? Support 5
dcantor How to? Can 32-bit TCC be run on a system with 64-bit TCMD and TCC installed? Support 6
G tcedit ist not run in tc 24 file explorer Support 10
A Windows 10 This app can't run on your PC Support 2
P Run as Admin tab in non-elevated Take Command session? Support 9
Roedy run as administrator Support 27
rps Documentation "Copy+Paste+run" question Support 2
Peter Murschall IDE/BDEBUUGER in TCC 22 didn't run Support 7
fpefpe How to? which will run? Support 1
C How to? run a BTM in elevated, inv tcc tab window Support 9
M How to? Run the control panel from a TCC session... Support 2
M How to? Run TCC from Windows Install DVD... Support 2
B Batch file won't run if there is already an instance of TC 17 running Support 9
P MS VS2013 vsdevcmd.bat fails to run with tcmd 17 x64 Support 10
redwdc btm won't run in ver. 17 but works in ver. 16 Support 11
C How to? run a batch file in administrator mode while debugging in take command software Support 1
Joe Caverly How to? Run DOS .exe's the same way Wine does... Support 3
tmaynard How to? Any way to run a command in a new tab at startup? Support 18
vefatica Why isn't TCSTART.BTM run? Support 8
M Installed but can't run Take Command 16.0 Support 5
D Run all .CMD batch files with CMD.EXE Support 16
Joe Caverly Run As Administrator in TCMD16 Support 3
F Sending "Y" to chkdsk to run on C at next reboot Support 25
T tcc /c "[...]" fails when run from third party terminal Support 11
B Select and run lines from Command Input panel? Support 1
Jay Sage Specified INI File Refuses to Run Support 3
A How to? Run a TCC command from external program Support 2
C How to? create a JPSoft BTM menu to run custom custom batch files Support 2
vefatica Coruption after which BTMs won't run Support 7
M How to? Run a command (alias, actually) on a "timed" basis... Support 13
Joe Caverly Copy Paste Run Support 12
S Fixed TCC.EXE 13.03.47 won't run Support 4
Stefano Piccardi run as limited user Support 2
M How to? Windows 7 - run TCC as admin w/o UAC intercept Support 4
E TCC requires elevation to run Support 2
Jay Sage How to Run Non-Elevated From Elevated TCC Support 1
L How can I run tcmd in terminal window only? Support 13

Similar threads