tags:

views:

245

answers:

3

Hey,

I am generating a Windows batch file that might become quite large, say a few megabytes. I've searched on possible limits regarding the maximum file size and maximum length of a line in a batch file but couldn't find anything. Any practical experiences?

+3  A: 

I think filesize can be anything up to 2 GB, perhaps even more. It's an interpreted language, so if this is done right, filesize limit should be the filesize limit of the file system. I never had any errors with batch files being too large, and some of those I created were several MBs in size.

There should be a line length limit, but it should be more than 256. This can easily be tested, just do some "set A=123456789012...endofline", after that "echo %A%", and you'll see how far you can go.

EDIT: Works for me with very long lines (around 4K), but at 8K echo gives a message "Line too long", so 8192 bytes should be some limit.

EDIT2: Now tested for filesize, too, tested with "echo off", thousands of set lines, after that "echo end", worked for a 11 MB file (although it took some seconds to finish :) - no limit in sight here.

Update: 110 MB worked, too. Is this enough? ;)

schnaader
nice. thanks for testing this for me :-) 8k sounds a lot, so I'll hope this is enough. Otherwise I could maybe split lines with this little hat ^?
zedoo
No, just tested, too. 8K seems to be an hard limit, even with splitting.
schnaader
Also note that this is for the final lines (with replaced variables), so echo %a%%a% will fail if %a% is a string longer than 4K!
schnaader
+1  A: 

some ideas, not necessarily mutually exclusive:

  • Switch to Powershell.
  • switch to a data-driven app, so that all the variable stuff is kept in a data file (csv, txt, whatever), and as a result you can have a smaller, boilerplate script that opens the data file and operates.
Cheeso
+1  A: 

It should work at least up to 2 GB. The lines are read directly from the BAT file on the disk (there is no caching involved). I make this statement because of the following:

In fact you can edit a BAT file while it is running! And it will work even though a text editor may rename the original version and save the new version in a new location on the disk. As long as you are careful not to insert text above the currently executing command. Lines can be changed/inserted/deleted below the currently executing command and the new lines will be the ones executed. I have often done this with BAT files containing a long list of wget commands, each taking tens of minutes to execute.

Peter Mortensen