Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process launch exception "filename or extension is too long", can it be caused by arg line and not filename? [duplicate]

Tags:

c#

process

I'm using System.Process to launch an external program, and I've just got a "filename or extension is too long" exception. However, I believe that filename is fine, but arguments is one hell of a long string (33,000 symbols). Can that string cause the exception?

like image 313
Violet Giraffe Avatar asked Oct 10 '13 21:10

Violet Giraffe


1 Answers

Yes. That text is the error message corresponding to ERROR_FILENAME_EXCED_RANGE, and other users report that it applies to the overall command length and not just the executable filename. See also

  • What processing/validation is performed on command line arguments before a process starts?

You are certainly exceeding the limit, although I agree the error message could be better. The CreateProcess documentation says:

lpCommandLine [in, out, optional]

The command line to be executed. The maximum length of this string is 32,768 characters, including the Unicode terminating null character. If lpApplicationName is NULL, the module name portion of lpCommandLine is limited to MAX_PATH characters.

For ShellExecute the limit is even lower. Hans linked a great blog series by Raymond Chen that discussed these limits and workarounds, see the question comments.

like image 147
Ben Voigt Avatar answered Sep 28 '22 03:09

Ben Voigt