The method below use a different approach:
Code: Select all
@echo off
setlocal EnableDelayedExpansion
set times=%1
echo 12345> test.dat
copy test.dat testBit.dat > NUL
< testBit.dat (for /L %%i in (0,1,30) do (
set /A "thisBit=times&1, times>>=1"
if !thisBit! equ 1 find /V "" >&2
if !times! neq 0 find /V ""
)) >> testBit.dat 2> testMillion.dat
del testBit.dat
A code block is opened with both Stdin and Stdout (in append mode) redirected to the auxiliary file, and Stderr redirected to the output file. When the auxiliary file needs to be appended to the output file, a
find /V "" >&2 command is executed; this
reset the file pointer of Stdin to the beginning of the auxiliary file, so all its contents is sent to the output file.
To duplicate the contents of the auxiliary file, a
find /V "" command is executed; this reset the file pointer of Stdin to the beginning of the auxiliary file again and append its contents to the end of the same file, because the Stdout pointer has not been moved. When I wrote this code I
expected that "find" command read the contents from Stdin at the moment it is executed,
before its contents be incremented because the "find" command itself...
Well, the interesting notice is that this method works!
The bad news is that it can only be used when "find" command can be used; the "more" command, that is the only other command that reset Stdin file pointer, fail when there are more than 64 k lines...
Antonio