Command line argument parameter limitation

Language: C # I have to pass a huge array of strings (built dynamically) as an argument to run exe. I think about understanding it in two ways. But I'm not sure of myself.

  • I can create it as a single line, limited to spaces. I can call exe through Process.Start. Therefore, the child process being executed considers the space and is held as a string array. However, I am not sure about the restriction of the string array. Suppose if the number of rows in an array exceeds 10,000

  • I can create it as one line limited by a special character that never gets into the data. I can call exe with a string. The descendant child process treats it as a single line, where I can split it with the same separator to return an array of strings. However, here I am not sure about the size of the team. Will this be done if the line length on the command line is large.

Can someone help me by showing me the parameter size limits

+8
source share
8 answers

It depends on the OS:

See the command line limit on the command line (Cmd. Exe) on the Microsoft support site.

On computers running Microsoft Windows XP or later, the maximum line length that you can use on the command line is 8191 characters . On computers running Microsoft Windows 2000 or Windows NT 4.0, the maximum line length that you can use on the command line is 2047 characters .

(emphasis mine)

As for the size of the string array - if you have many millions of rows in a string array, you are basically limited by the amount of available memory.

+16
source

Although a bad idea, Process.start with useshellexecute=false will call createprocess() , which allows 32,767 characters on the command line (although this is also the maximum size for the entire environment block)

+6
source

If you pass 10,000 arguments to a program, you must put these arguments in a file and read the file from disk.

+5
source

You can save the arguments in a text file and pass that text file as an argument. Your application can then parse the text file to parse the arguments.

+3
source

It is actually not a good practice to use command line arguments for huge arrays. Instead, put your arguments in a configuration file and simply pass the file name as a command line argument.

The OS limitation depends on the version of Windows. It could be around 2k or 8k:

http://support.microsoft.com/kb/830473

+1
source

You might want to create a parameter file and pass the file as a parameter.

I found this:

For the OS: the maximum command line length is 32767 characters (this restriction applies to the Unicode string structure), the maximum command line length is 8192 characters (this limit is from cmd.exe). You can also check:

http://support.microsoft.com/kb/830473

I hope for this help.

+1
source
  • The limit on the command line (Cmd. Exe) is 8191. The limit on the command line on the command line (Cmd. Exe )
  • The limitation in C # code using Process is 32768 characters in win10.
  • Tested using Process.start ()
0
source

If starting the child process directly from the parent process is acceptable ( UseShellExecute = false ), you can redirect the StandardInput child process and pass an arbitrary data size by throwing it away. Here is an example of passing an array of 100,000 lines and other things, serialization in binary format.

 static void Main(string[] args) { if (args.Length == 0) { var exeFilePath = Assembly.GetExecutingAssembly().Location; var psi = new ProcessStartInfo(exeFilePath, "CHILD"); psi.UseShellExecute = false; psi.RedirectStandardInput = true; Console.WriteLine("Parent - Starting child process"); var childProcess = Process.Start(psi); var bf = new BinaryFormatter(); object[] data = Enumerable.Range(1, 100000) .Select(i => (object)$"String-{i}") .Append(13) .Append(DateTime.Now) .Append(new DataTable("Customers")) .ToArray(); Console.WriteLine("Parent - Sending data"); bf.Serialize(childProcess.StandardInput.BaseStream, data); Console.WriteLine("Parent - WaitForExit"); childProcess.WaitForExit(); Console.WriteLine("Parent - Closing"); } else { Console.WriteLine("Child - Started"); var bf = new BinaryFormatter(); Console.WriteLine("Child - Reading data"); var data = (object[])bf.Deserialize(Console.OpenStandardInput()); Console.WriteLine($"Child - Data.Length: {data.Length}"); Console.WriteLine("Child - Closing"); } } 

Exit:

Parent - Starting a child process
Baby - Started
Child - Reading Data
Parent - sending data
Parent - WaitForExit
Child - Data. Length: 100003
Baby - Closing
Parent - Closing

This example runs in 6 seconds on my machine.

0
source

All Articles