Drag & Drop Batch files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Drag & Drop Batch files

#1 Post by Squashman » 30 Dec 2011 11:18

Just some friendly discussion on the input length restriction of 2048 bytes for drag and drop onto a batch file. I had mentioned it to aGerman in some private messages and he suggested we start a thread about it. I use drag & drop to process specific files in a directory. It also makes it easier for the user. Some of the people I work with really fear using batch files so I figured it would make it easier for them if they could just drag the files they need to process onto the batch file.

The Microsoft KB article doesn't mention anything about this limitation.
http://support.microsoft.com/kb/830473/en-us

I have been a kid in a candy store since I joined this forum and I was reading one of the Macro threads and I found the following comment in the How Batch Macros Work thread.
Ed Dyreen wrote:The amount of characters a variable can contain, is limited !
( The "normal" maximum line length is ~8192, the maximum line length for drag&drop operations is ~2048. And even the 8192 can be exceeded with an FOR /F loop. jeb )


The 2048 seems to be the limitation for XP. But I found out that the limitation for Windows 7 seems to be 4096. I can't remember if I tested that on 32 or 64 bit.

What is interesting is that you get a Windows Popup with an error message when you try and drag and drop more than 2048 bytes of input onto a batch file.

Hoping Jeb or Ed can shed some light on this subject.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Drag & Drop Batch files

#2 Post by aGerman » 31 Dec 2011 08:08

My guess is that dropped files come in as an array and a defined amount of memory space is allocated for the arguments array. If the arguments list is greater than the allocated space it causes a buffer overflow.

Squashman wrote:What is interesting is that you get a Windows Popup with an error message when you try and drag and drop more than 2048 bytes of input onto a batch file.

EDIT wrong[ Hmm, even if I drop more onto a batch file I don't get an error message (Win7). If I try to echo %* it displays the number of files till the maximum length is reached. If the last (full) name isn't complete then it is stripped from displaying. ]

Regards
aGerman

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Drag & Drop Batch files

#3 Post by aGerman » 01 Jan 2012 12:15

For some reason I must have done something wrong yesterday :?

Some more tests today show the following results [Win7]:
- The number of characters you can drop to a batch file varies with the length of the batch full name. That's obvious since you can find the "own call" in %0.
- In my tests I was able to drop 8181 - (number of separating spaces) - (length of batch full name) characters and display them (echo %*)
- If it is less more than this amount, the batch interrupts with a message that the command line is too long.
- If I try to drop much more than this amount (currently I was not able to find the limit) I get the Windows error popup.

Regards
aGerman

Squashman
Expert
Posts: 4471
Joined: 23 Dec 2011 13:59

Re: Drag & Drop Batch files

#4 Post by Squashman » 01 Jan 2012 18:51

On Windows 7 were you testing on 32 or 64 bit? I swear I had tested on 32bit and it bombed at 4096 bytes of input. Maybe I didn't test very well. It is good to know that Windows 7 allows more input.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Drag & Drop Batch files

#5 Post by aGerman » 01 Jan 2012 18:53

It's a 32 Bit system.

Regards
aGerman

Post Reply