Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get around the command line length limit?

I've been working on a small and simple program that I drop files onto and, based on certian rules, they are moved to diffrent places.

The program works fine unless I drop more than a few files, then it kicks back an error (that appears to be more Windows than anything) that the start up command "c:\myapp.exe \file \file \file" is too long.

I realize I could set up a background proccess, but I really would prefer that this program not run in the backround (where it would be idle most of the time).

Is there a way around this limitation?

like image 842
Crash893 Avatar asked May 26 '10 21:05

Crash893


People also ask

How long can command line arguments be?

More information. The maximum length of the string that you can use at the command prompt is 8191 characters. This limitation applies to: the command line.

How do you increase a line in command prompt?

If you're using windows , click on the CMD icon in the top left corner and go to properties. Click the Options tab. In Command History, type or select 999 in Buffer Size, and then type or select 5 in Number of Buffers.

How do I skip a space in command prompt?

In the Command Prompt, the caret character ( ^ ) will let you escape spaces—in theory. Just add it before each space in the file name. (You'll find this character in the number row on your keyboard.

What is the max length of Linux command line?

The maximum line length is 4096 chars (including the terminating newline character); lines longer than 4096 chars are truncated. After 4095 characters, input processing (e.g., ISIG and ECHO* processing) continues, but any input data after 4095 characters up to (but not including) any terminating newline is discarded.


2 Answers

From this blog:

  • The maximum command line length for the CreateProcess function is 32767 characters. This limitation comes from the UNICODE_STRING structure.
  • If you are using the CMD.EXE command processor, then you are also subject to the 8192 character command line length limit imposed by CMD.EXE.
  • If you are using the ShellExecute/Ex function, then you become subject to the INTERNET_MAX_URL_LENGTH (around 2048) command line length limit imposed by the ShellExecute/Ex functions.
  • The maximum size of your environment is 32767 characters. The size of the environment includes all the variable names plus all the values.

So you're gonna have to settle with some of the mentioned workarounds (also, there's another workaround on the msdn blog I linked).

like image 83
GnP Avatar answered Oct 07 '22 19:10

GnP


If you want to drop files with respect of Windows Explorer, then you can implement your own Drop Handlers as a Shell Extension Handlers see:

  • How to Create Drop Handlers (Windows)
  • Creating Shell Extension Handlers

On The Complete Idiot's Guide to Writing Shell Extensions you will find a good introduction how to write such extensions.

The part VI gives an example of Drop Handler (for a little other use case, but it dose not matter).

With respect of Drop Shell Extension Handler your program will receive full information about all dropped files and you need not start a child program with all the files as command like parameters.

like image 21
Oleg Avatar answered Oct 07 '22 21:10

Oleg