TYPE bug?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

TYPE bug?

#1 Post by einstein1969 » 25 Feb 2016 16:15

Hi,

I have answered at this question:http://stackoverflow.com/questions/35620974/how-to-repeat-given-hex-string/35636769#35636769. In the original i have tested this code that use TYPE instead of COPY:

Code: Select all

@echo off
setlocal EnableDelayedExpansion

echo %time%

>test.dat set /p ".=1234567" <nul
copy test.dat /B tmp.dat >nul

set Times=255

(
 for /l %%n in (1,1,32) do (
    set /A "bit=Times %% 2, Times/=2"
    If !bit! equ 1 type tmp.dat
    if !Times! gtr 0 Type tmp.dat>>tmp.dat
 )
) > milliontest.dat

del tmp.dat
echo %time%

dir milliontest.dat

pause

exit /b


This work with TIMES until 255. From 256 the :

Code: Select all

Type tmp.dat>>tmp.dat


fail. Why?

EDIT: tested on Windows 7 32 bit

Einstein1969

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TYPE bug?

#2 Post by Aacini » 25 Feb 2016 19:08

Wow! I couldn't belive this at first, but after completed some tests it seems that your conclusion is right: in this condition TYPE command fail!

Code: Select all

@echo off
setlocal EnableDelayedExpansion

set times=%1

set /p "=1234567" > test.dat < NUL
copy test.dat testBit.dat > NUL

(for /L %%i in (0,1,30) do if !times! neq 0 (

   set /A "thisBit=times&1, times>>=1"
   if !thisBit! equ 1 type testBit.dat
   if !times! neq 0 (

      REM Next line fail!
      REM type testBit.dat >> testBit.dat

      REM This works, but it is slower
      copy testBit.dat+testBit.dat /B testBitX2.dat > NUL
      move /Y testBitX2.dat testBit.dat > NUL
   )

)) > testMillion.dat

del testBit.dat

Antonio

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: TYPE bug?

#3 Post by dbenham » 25 Feb 2016 20:51

I am not shocked that it does not give the "expected" results. I was dubious as to whether TYPE could safely write to the same file it was reading from. So I was pleasantly surprised when I first attempted to do it at viewtopic.php?f=3&t=1226&start=30#p7037. TYPE must capture and remember the end-of-file position before it begins writing, and then stop when it reaches the initial end-of-file. Otherwise it would never end.

It seems to work perfectly as long as the file length is a power of 2 - it exactly doubles in length each time.

But if the length is not a power of 2, then it begins writing extra bytes once the length exceeds some threshold (in the hundreds). I find it interesting that the number of extra bytes per iteration is a constant for any given starting length.

There is definitely a pattern that seemingly could be deciphered, but I don't know what it is. I'll leave the puzzle for others to figure out :mrgreen:

Here is a simple test to get started:

Code: Select all

@echo off
setlocal EnableDelayedExpansion
for /l %%N in (1 1 32) do call :test %%N
exit /b

:test initialLength

  >test.dat <nul (
    for /l %%N in (1 1 %1) do set /p "=1"
  )

  for %%F in (test.dat) do set /a start=%%~zF
  echo initial length = %start%

  9>>test.dat (
   for /l %%n in (1,1,15) do (
     type test.dat >&9
     for %%F in (test.dat) do set /a expected=start*2, actual=%%~zF, diff=actual-expected
     echo start=!start!  expected=!expected!  actual=!actual!  difference=!diff!
     set /a start=actual
   )
  )
  echo(

exit /b

And here is the output

Code: Select all

initial length = 1
start=1  expected=2  actual=2  difference=0
start=2  expected=4  actual=4  difference=0
start=4  expected=8  actual=8  difference=0
start=8  expected=16  actual=16  difference=0
start=16  expected=32  actual=32  difference=0
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0

initial length = 2
start=2  expected=4  actual=4  difference=0
start=4  expected=8  actual=8  difference=0
start=8  expected=16  actual=16  difference=0
start=16  expected=32  actual=32  difference=0
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0
start=32768  expected=65536  actual=65536  difference=0

initial length = 3
start=3  expected=6  actual=6  difference=0
start=6  expected=12  actual=12  difference=0
start=12  expected=24  actual=24  difference=0
start=24  expected=48  actual=48  difference=0
start=48  expected=96  actual=96  difference=0
start=96  expected=192  actual=192  difference=0
start=192  expected=384  actual=384  difference=0
start=384  expected=768  actual=768  difference=0
start=768  expected=1536  actual=1792  difference=256
start=1792  expected=3584  actual=3840  difference=256
start=3840  expected=7680  actual=7936  difference=256
start=7936  expected=15872  actual=16128  difference=256
start=16128  expected=32256  actual=32512  difference=256
start=32512  expected=65024  actual=65280  difference=256
start=65280  expected=130560  actual=130816  difference=256

initial length = 4
start=4  expected=8  actual=8  difference=0
start=8  expected=16  actual=16  difference=0
start=16  expected=32  actual=32  difference=0
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0
start=32768  expected=65536  actual=65536  difference=0
start=65536  expected=131072  actual=131072  difference=0

initial length = 5
start=5  expected=10  actual=10  difference=0
start=10  expected=20  actual=20  difference=0
start=20  expected=40  actual=40  difference=0
start=40  expected=80  actual=80  difference=0
start=80  expected=160  actual=160  difference=0
start=160  expected=320  actual=320  difference=0
start=320  expected=640  actual=640  difference=0
start=640  expected=1280  actual=1664  difference=384
start=1664  expected=3328  actual=3712  difference=384
start=3712  expected=7424  actual=7808  difference=384
start=7808  expected=15616  actual=16000  difference=384
start=16000  expected=32000  actual=32384  difference=384
start=32384  expected=64768  actual=65152  difference=384
start=65152  expected=130304  actual=130688  difference=384
start=130688  expected=261376  actual=261760  difference=384

initial length = 6
start=6  expected=12  actual=12  difference=0
start=12  expected=24  actual=24  difference=0
start=24  expected=48  actual=48  difference=0
start=48  expected=96  actual=96  difference=0
start=96  expected=192  actual=192  difference=0
start=192  expected=384  actual=384  difference=0
start=384  expected=768  actual=768  difference=0
start=768  expected=1536  actual=1792  difference=256
start=1792  expected=3584  actual=3840  difference=256
start=3840  expected=7680  actual=7936  difference=256
start=7936  expected=15872  actual=16128  difference=256
start=16128  expected=32256  actual=32512  difference=256
start=32512  expected=65024  actual=65280  difference=256
start=65280  expected=130560  actual=130816  difference=256
start=130816  expected=261632  actual=261888  difference=256

initial length = 7
start=7  expected=14  actual=14  difference=0
start=14  expected=28  actual=28  difference=0
start=28  expected=56  actual=56  difference=0
start=56  expected=112  actual=112  difference=0
start=112  expected=224  actual=224  difference=0
start=224  expected=448  actual=448  difference=0
start=448  expected=896  actual=896  difference=0
start=896  expected=1792  actual=1920  difference=128
start=1920  expected=3840  actual=3968  difference=128
start=3968  expected=7936  actual=8064  difference=128
start=8064  expected=16128  actual=16256  difference=128
start=16256  expected=32512  actual=32640  difference=128
start=32640  expected=65280  actual=65408  difference=128
start=65408  expected=130816  actual=130944  difference=128
start=130944  expected=261888  actual=262016  difference=128

initial length = 8
start=8  expected=16  actual=16  difference=0
start=16  expected=32  actual=32  difference=0
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0
start=32768  expected=65536  actual=65536  difference=0
start=65536  expected=131072  actual=131072  difference=0
start=131072  expected=262144  actual=262144  difference=0

initial length = 9
start=9  expected=18  actual=18  difference=0
start=18  expected=36  actual=36  difference=0
start=36  expected=72  actual=72  difference=0
start=72  expected=144  actual=144  difference=0
start=144  expected=288  actual=288  difference=0
start=288  expected=576  actual=576  difference=0
start=576  expected=1152  actual=1600  difference=448
start=1600  expected=3200  actual=3648  difference=448
start=3648  expected=7296  actual=7744  difference=448
start=7744  expected=15488  actual=15936  difference=448
start=15936  expected=31872  actual=32320  difference=448
start=32320  expected=64640  actual=65088  difference=448
start=65088  expected=130176  actual=130624  difference=448
start=130624  expected=261248  actual=261696  difference=448
start=261696  expected=523392  actual=523840  difference=448

initial length = 10
start=10  expected=20  actual=20  difference=0
start=20  expected=40  actual=40  difference=0
start=40  expected=80  actual=80  difference=0
start=80  expected=160  actual=160  difference=0
start=160  expected=320  actual=320  difference=0
start=320  expected=640  actual=640  difference=0
start=640  expected=1280  actual=1664  difference=384
start=1664  expected=3328  actual=3712  difference=384
start=3712  expected=7424  actual=7808  difference=384
start=7808  expected=15616  actual=16000  difference=384
start=16000  expected=32000  actual=32384  difference=384
start=32384  expected=64768  actual=65152  difference=384
start=65152  expected=130304  actual=130688  difference=384
start=130688  expected=261376  actual=261760  difference=384
start=261760  expected=523520  actual=523904  difference=384

initial length = 11
start=11  expected=22  actual=22  difference=0
start=22  expected=44  actual=44  difference=0
start=44  expected=88  actual=88  difference=0
start=88  expected=176  actual=176  difference=0
start=176  expected=352  actual=352  difference=0
start=352  expected=704  actual=704  difference=0
start=704  expected=1408  actual=1728  difference=320
start=1728  expected=3456  actual=3776  difference=320
start=3776  expected=7552  actual=7872  difference=320
start=7872  expected=15744  actual=16064  difference=320
start=16064  expected=32128  actual=32448  difference=320
start=32448  expected=64896  actual=65216  difference=320
start=65216  expected=130432  actual=130752  difference=320
start=130752  expected=261504  actual=261824  difference=320
start=261824  expected=523648  actual=523968  difference=320

initial length = 12
start=12  expected=24  actual=24  difference=0
start=24  expected=48  actual=48  difference=0
start=48  expected=96  actual=96  difference=0
start=96  expected=192  actual=192  difference=0
start=192  expected=384  actual=384  difference=0
start=384  expected=768  actual=768  difference=0
start=768  expected=1536  actual=1792  difference=256
start=1792  expected=3584  actual=3840  difference=256
start=3840  expected=7680  actual=7936  difference=256
start=7936  expected=15872  actual=16128  difference=256
start=16128  expected=32256  actual=32512  difference=256
start=32512  expected=65024  actual=65280  difference=256
start=65280  expected=130560  actual=130816  difference=256
start=130816  expected=261632  actual=261888  difference=256
start=261888  expected=523776  actual=524032  difference=256

initial length = 13
start=13  expected=26  actual=26  difference=0
start=26  expected=52  actual=52  difference=0
start=52  expected=104  actual=104  difference=0
start=104  expected=208  actual=208  difference=0
start=208  expected=416  actual=416  difference=0
start=416  expected=832  actual=832  difference=0
start=832  expected=1664  actual=1856  difference=192
start=1856  expected=3712  actual=3904  difference=192
start=3904  expected=7808  actual=8000  difference=192
start=8000  expected=16000  actual=16192  difference=192
start=16192  expected=32384  actual=32576  difference=192
start=32576  expected=65152  actual=65344  difference=192
start=65344  expected=130688  actual=130880  difference=192
start=130880  expected=261760  actual=261952  difference=192
start=261952  expected=523904  actual=524096  difference=192

initial length = 14
start=14  expected=28  actual=28  difference=0
start=28  expected=56  actual=56  difference=0
start=56  expected=112  actual=112  difference=0
start=112  expected=224  actual=224  difference=0
start=224  expected=448  actual=448  difference=0
start=448  expected=896  actual=896  difference=0
start=896  expected=1792  actual=1920  difference=128
start=1920  expected=3840  actual=3968  difference=128
start=3968  expected=7936  actual=8064  difference=128
start=8064  expected=16128  actual=16256  difference=128
start=16256  expected=32512  actual=32640  difference=128
start=32640  expected=65280  actual=65408  difference=128
start=65408  expected=130816  actual=130944  difference=128
start=130944  expected=261888  actual=262016  difference=128
start=262016  expected=524032  actual=524160  difference=128

initial length = 15
start=15  expected=30  actual=30  difference=0
start=30  expected=60  actual=60  difference=0
start=60  expected=120  actual=120  difference=0
start=120  expected=240  actual=240  difference=0
start=240  expected=480  actual=480  difference=0
start=480  expected=960  actual=960  difference=0
start=960  expected=1920  actual=1984  difference=64
start=1984  expected=3968  actual=4032  difference=64
start=4032  expected=8064  actual=8128  difference=64
start=8128  expected=16256  actual=16320  difference=64
start=16320  expected=32640  actual=32704  difference=64
start=32704  expected=65408  actual=65472  difference=64
start=65472  expected=130944  actual=131008  difference=64
start=131008  expected=262016  actual=262080  difference=64
start=262080  expected=524160  actual=524224  difference=64

initial length = 16
start=16  expected=32  actual=32  difference=0
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0
start=32768  expected=65536  actual=65536  difference=0
start=65536  expected=131072  actual=131072  difference=0
start=131072  expected=262144  actual=262144  difference=0
start=262144  expected=524288  actual=524288  difference=0

initial length = 17
start=17  expected=34  actual=34  difference=0
start=34  expected=68  actual=68  difference=0
start=68  expected=136  actual=136  difference=0
start=136  expected=272  actual=272  difference=0
start=272  expected=544  actual=544  difference=0
start=544  expected=1088  actual=1568  difference=480
start=1568  expected=3136  actual=3616  difference=480
start=3616  expected=7232  actual=7712  difference=480
start=7712  expected=15424  actual=15904  difference=480
start=15904  expected=31808  actual=32288  difference=480
start=32288  expected=64576  actual=65056  difference=480
start=65056  expected=130112  actual=130592  difference=480
start=130592  expected=261184  actual=261664  difference=480
start=261664  expected=523328  actual=523808  difference=480
start=523808  expected=1047616  actual=1048096  difference=480

initial length = 18
start=18  expected=36  actual=36  difference=0
start=36  expected=72  actual=72  difference=0
start=72  expected=144  actual=144  difference=0
start=144  expected=288  actual=288  difference=0
start=288  expected=576  actual=576  difference=0
start=576  expected=1152  actual=1600  difference=448
start=1600  expected=3200  actual=3648  difference=448
start=3648  expected=7296  actual=7744  difference=448
start=7744  expected=15488  actual=15936  difference=448
start=15936  expected=31872  actual=32320  difference=448
start=32320  expected=64640  actual=65088  difference=448
start=65088  expected=130176  actual=130624  difference=448
start=130624  expected=261248  actual=261696  difference=448
start=261696  expected=523392  actual=523840  difference=448
start=523840  expected=1047680  actual=1048128  difference=448

initial length = 19
start=19  expected=38  actual=38  difference=0
start=38  expected=76  actual=76  difference=0
start=76  expected=152  actual=152  difference=0
start=152  expected=304  actual=304  difference=0
start=304  expected=608  actual=608  difference=0
start=608  expected=1216  actual=1632  difference=416
start=1632  expected=3264  actual=3680  difference=416
start=3680  expected=7360  actual=7776  difference=416
start=7776  expected=15552  actual=15968  difference=416
start=15968  expected=31936  actual=32352  difference=416
start=32352  expected=64704  actual=65120  difference=416
start=65120  expected=130240  actual=130656  difference=416
start=130656  expected=261312  actual=261728  difference=416
start=261728  expected=523456  actual=523872  difference=416
start=523872  expected=1047744  actual=1048160  difference=416

initial length = 20
start=20  expected=40  actual=40  difference=0
start=40  expected=80  actual=80  difference=0
start=80  expected=160  actual=160  difference=0
start=160  expected=320  actual=320  difference=0
start=320  expected=640  actual=640  difference=0
start=640  expected=1280  actual=1664  difference=384
start=1664  expected=3328  actual=3712  difference=384
start=3712  expected=7424  actual=7808  difference=384
start=7808  expected=15616  actual=16000  difference=384
start=16000  expected=32000  actual=32384  difference=384
start=32384  expected=64768  actual=65152  difference=384
start=65152  expected=130304  actual=130688  difference=384
start=130688  expected=261376  actual=261760  difference=384
start=261760  expected=523520  actual=523904  difference=384
start=523904  expected=1047808  actual=1048192  difference=384

initial length = 21
start=21  expected=42  actual=42  difference=0
start=42  expected=84  actual=84  difference=0
start=84  expected=168  actual=168  difference=0
start=168  expected=336  actual=336  difference=0
start=336  expected=672  actual=672  difference=0
start=672  expected=1344  actual=1696  difference=352
start=1696  expected=3392  actual=3744  difference=352
start=3744  expected=7488  actual=7840  difference=352
start=7840  expected=15680  actual=16032  difference=352
start=16032  expected=32064  actual=32416  difference=352
start=32416  expected=64832  actual=65184  difference=352
start=65184  expected=130368  actual=130720  difference=352
start=130720  expected=261440  actual=261792  difference=352
start=261792  expected=523584  actual=523936  difference=352
start=523936  expected=1047872  actual=1048224  difference=352

initial length = 22
start=22  expected=44  actual=44  difference=0
start=44  expected=88  actual=88  difference=0
start=88  expected=176  actual=176  difference=0
start=176  expected=352  actual=352  difference=0
start=352  expected=704  actual=704  difference=0
start=704  expected=1408  actual=1728  difference=320
start=1728  expected=3456  actual=3776  difference=320
start=3776  expected=7552  actual=7872  difference=320
start=7872  expected=15744  actual=16064  difference=320
start=16064  expected=32128  actual=32448  difference=320
start=32448  expected=64896  actual=65216  difference=320
start=65216  expected=130432  actual=130752  difference=320
start=130752  expected=261504  actual=261824  difference=320
start=261824  expected=523648  actual=523968  difference=320
start=523968  expected=1047936  actual=1048256  difference=320

initial length = 23
start=23  expected=46  actual=46  difference=0
start=46  expected=92  actual=92  difference=0
start=92  expected=184  actual=184  difference=0
start=184  expected=368  actual=368  difference=0
start=368  expected=736  actual=736  difference=0
start=736  expected=1472  actual=1760  difference=288
start=1760  expected=3520  actual=3808  difference=288
start=3808  expected=7616  actual=7904  difference=288
start=7904  expected=15808  actual=16096  difference=288
start=16096  expected=32192  actual=32480  difference=288
start=32480  expected=64960  actual=65248  difference=288
start=65248  expected=130496  actual=130784  difference=288
start=130784  expected=261568  actual=261856  difference=288
start=261856  expected=523712  actual=524000  difference=288
start=524000  expected=1048000  actual=1048288  difference=288

initial length = 24
start=24  expected=48  actual=48  difference=0
start=48  expected=96  actual=96  difference=0
start=96  expected=192  actual=192  difference=0
start=192  expected=384  actual=384  difference=0
start=384  expected=768  actual=768  difference=0
start=768  expected=1536  actual=1792  difference=256
start=1792  expected=3584  actual=3840  difference=256
start=3840  expected=7680  actual=7936  difference=256
start=7936  expected=15872  actual=16128  difference=256
start=16128  expected=32256  actual=32512  difference=256
start=32512  expected=65024  actual=65280  difference=256
start=65280  expected=130560  actual=130816  difference=256
start=130816  expected=261632  actual=261888  difference=256
start=261888  expected=523776  actual=524032  difference=256
start=524032  expected=1048064  actual=1048320  difference=256

initial length = 25
start=25  expected=50  actual=50  difference=0
start=50  expected=100  actual=100  difference=0
start=100  expected=200  actual=200  difference=0
start=200  expected=400  actual=400  difference=0
start=400  expected=800  actual=800  difference=0
start=800  expected=1600  actual=1824  difference=224
start=1824  expected=3648  actual=3872  difference=224
start=3872  expected=7744  actual=7968  difference=224
start=7968  expected=15936  actual=16160  difference=224
start=16160  expected=32320  actual=32544  difference=224
start=32544  expected=65088  actual=65312  difference=224
start=65312  expected=130624  actual=130848  difference=224
start=130848  expected=261696  actual=261920  difference=224
start=261920  expected=523840  actual=524064  difference=224
start=524064  expected=1048128  actual=1048352  difference=224

initial length = 26
start=26  expected=52  actual=52  difference=0
start=52  expected=104  actual=104  difference=0
start=104  expected=208  actual=208  difference=0
start=208  expected=416  actual=416  difference=0
start=416  expected=832  actual=832  difference=0
start=832  expected=1664  actual=1856  difference=192
start=1856  expected=3712  actual=3904  difference=192
start=3904  expected=7808  actual=8000  difference=192
start=8000  expected=16000  actual=16192  difference=192
start=16192  expected=32384  actual=32576  difference=192
start=32576  expected=65152  actual=65344  difference=192
start=65344  expected=130688  actual=130880  difference=192
start=130880  expected=261760  actual=261952  difference=192
start=261952  expected=523904  actual=524096  difference=192
start=524096  expected=1048192  actual=1048384  difference=192

initial length = 27
start=27  expected=54  actual=54  difference=0
start=54  expected=108  actual=108  difference=0
start=108  expected=216  actual=216  difference=0
start=216  expected=432  actual=432  difference=0
start=432  expected=864  actual=864  difference=0
start=864  expected=1728  actual=1888  difference=160
start=1888  expected=3776  actual=3936  difference=160
start=3936  expected=7872  actual=8032  difference=160
start=8032  expected=16064  actual=16224  difference=160
start=16224  expected=32448  actual=32608  difference=160
start=32608  expected=65216  actual=65376  difference=160
start=65376  expected=130752  actual=130912  difference=160
start=130912  expected=261824  actual=261984  difference=160
start=261984  expected=523968  actual=524128  difference=160
start=524128  expected=1048256  actual=1048416  difference=160

initial length = 28
start=28  expected=56  actual=56  difference=0
start=56  expected=112  actual=112  difference=0
start=112  expected=224  actual=224  difference=0
start=224  expected=448  actual=448  difference=0
start=448  expected=896  actual=896  difference=0
start=896  expected=1792  actual=1920  difference=128
start=1920  expected=3840  actual=3968  difference=128
start=3968  expected=7936  actual=8064  difference=128
start=8064  expected=16128  actual=16256  difference=128
start=16256  expected=32512  actual=32640  difference=128
start=32640  expected=65280  actual=65408  difference=128
start=65408  expected=130816  actual=130944  difference=128
start=130944  expected=261888  actual=262016  difference=128
start=262016  expected=524032  actual=524160  difference=128
start=524160  expected=1048320  actual=1048448  difference=128

initial length = 29
start=29  expected=58  actual=58  difference=0
start=58  expected=116  actual=116  difference=0
start=116  expected=232  actual=232  difference=0
start=232  expected=464  actual=464  difference=0
start=464  expected=928  actual=928  difference=0
start=928  expected=1856  actual=1952  difference=96
start=1952  expected=3904  actual=4000  difference=96
start=4000  expected=8000  actual=8096  difference=96
start=8096  expected=16192  actual=16288  difference=96
start=16288  expected=32576  actual=32672  difference=96
start=32672  expected=65344  actual=65440  difference=96
start=65440  expected=130880  actual=130976  difference=96
start=130976  expected=261952  actual=262048  difference=96
start=262048  expected=524096  actual=524192  difference=96
start=524192  expected=1048384  actual=1048480  difference=96

initial length = 30
start=30  expected=60  actual=60  difference=0
start=60  expected=120  actual=120  difference=0
start=120  expected=240  actual=240  difference=0
start=240  expected=480  actual=480  difference=0
start=480  expected=960  actual=960  difference=0
start=960  expected=1920  actual=1984  difference=64
start=1984  expected=3968  actual=4032  difference=64
start=4032  expected=8064  actual=8128  difference=64
start=8128  expected=16256  actual=16320  difference=64
start=16320  expected=32640  actual=32704  difference=64
start=32704  expected=65408  actual=65472  difference=64
start=65472  expected=130944  actual=131008  difference=64
start=131008  expected=262016  actual=262080  difference=64
start=262080  expected=524160  actual=524224  difference=64
start=524224  expected=1048448  actual=1048512  difference=64

initial length = 31
start=31  expected=62  actual=62  difference=0
start=62  expected=124  actual=124  difference=0
start=124  expected=248  actual=248  difference=0
start=248  expected=496  actual=496  difference=0
start=496  expected=992  actual=992  difference=0
start=992  expected=1984  actual=2016  difference=32
start=2016  expected=4032  actual=4064  difference=32
start=4064  expected=8128  actual=8160  difference=32
start=8160  expected=16320  actual=16352  difference=32
start=16352  expected=32704  actual=32736  difference=32
start=32736  expected=65472  actual=65504  difference=32
start=65504  expected=131008  actual=131040  difference=32
start=131040  expected=262080  actual=262112  difference=32
start=262112  expected=524224  actual=524256  difference=32
start=524256  expected=1048512  actual=1048544  difference=32

initial length = 32
start=32  expected=64  actual=64  difference=0
start=64  expected=128  actual=128  difference=0
start=128  expected=256  actual=256  difference=0
start=256  expected=512  actual=512  difference=0
start=512  expected=1024  actual=1024  difference=0
start=1024  expected=2048  actual=2048  difference=0
start=2048  expected=4096  actual=4096  difference=0
start=4096  expected=8192  actual=8192  difference=0
start=8192  expected=16384  actual=16384  difference=0
start=16384  expected=32768  actual=32768  difference=0
start=32768  expected=65536  actual=65536  difference=0
start=65536  expected=131072  actual=131072  difference=0
start=131072  expected=262144  actual=262144  difference=0
start=262144  expected=524288  actual=524288  difference=0
start=524288  expected=1048576  actual=1048576  difference=0


Dave Benham

pieh-ejdsch
Posts: 240
Joined: 04 Mar 2014 11:14
Location: germany

Re: TYPE bug?

#4 Post by pieh-ejdsch » 28 Feb 2016 08:55

The output redirection writes exactly 1024 bytes.
The selection EOF disappears at the moment as the file to write is opened.
The processing of type recognises this selection EOF if 1024 bytes were read and this selection was present.
Now for unexplicable reasons it is selected instead of the old selection EOF 1024 bytes of border as the selection EOF. Whether this holy number now 1024 or 512 bytes is, however, I cannot exactly say.
In any case, the difference of the doubled file to the source file always amounts to 1024 bytes when the size of the source file does not amount more than 1024 bytes. (Test with 768)
If the source file is bigger than 1024 bytes this difference always amounts multiple from 512. (test with 1500)
If the size of the source file is only half multiple from 1024 bytes the result also always suits.


I think it no bug is in this case, to type behaves always immediately: "512 bytes are read and displayed".
At most 511 bytes Are redirected from the beginning of the file once more in the same file to the end.

Phil

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TYPE bug?

#5 Post by Aacini » 28 Feb 2016 11:52

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! :shock: 8) 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

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: TYPE bug?

#6 Post by dbenham » 28 Feb 2016 12:17

Nice approach. However, FIND terminates every line of output with <CR><LF>. So your FIND method is only good if you can guarantee every line within the source is already terminated by <CR><LF>.


Dave Benham

Aacini
Expert
Posts: 1914
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: TYPE bug?

#7 Post by Aacini » 28 Feb 2016 12:40

Yes, I know that:

Aacini wrote:The bad news is that it can only be used when "find" command can be used...


Antonio

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: TYPE bug?

#8 Post by dbenham » 28 Feb 2016 13:16

Ahh... yes. The significance of that statement passed me by.

I'm aware that FINDSTR cannot print out a line longer than 4096 bytes.

Any other limitations you are aware of?

einstein1969
Expert
Posts: 961
Joined: 15 Jun 2012 13:16
Location: Italy, Rome

Re: TYPE bug?

#9 Post by einstein1969 » 01 Mar 2016 16:01

Aacini wrote: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! :shock: 8) 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


I can not imagine how it can work even though you have explained very well. They are light years away from understanding of this piece of code. It 's really brilliant 8)

I have problems with multi redirect of a block, especially when interacting with the find or findstr and the FOR. If you have any link as a reference to better understand / learn is welcome.

Einstein1969

Post Reply