As @Sugrue I'm also digging out an old thread.
To explain why there is 32768 (I think it should be 32767, but lets believe experimental testing result) characters limitation we need to dig into Windows API.
No matter how you launch program with command line arguments it goes to ShellExecute, CreateProcess or any extended their version. These APIs basically wrap other NT level API that are not officially documented. As far as I know these calls wrap NtCreateProcess, which requires OBJECT_ATTRIBUTES structure as a parameter, to create that structure InitializeObjectAttributes is used. In this place we see UNICODE_STRING
. So now lets take a look into this structure:
typedef struct _UNICODE_STRING {
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} UNICODE_STRING;
It uses USHORT
(16-bit length [0; 65535]) variable to store length. And according this, length indicates size in bytes, not characters. So we have: 65535 / 2 = 32767
(because WCHAR
is 2 bytes long).
There are a few steps to dig into this number, but I hope it is clear.
Also, to support @sunetos answer what is accepted. 8191 is a maximum number allowed to be entered into cmd.exe
, if you exceed this limit, The input line is too long.
error is generated. So, answer is correct despite the fact that cmd.exe
is not the only way to pass arguments for new process.