Search code examples
javaprocessbuilder

Maximum length of string argument in java processbuilder


I know there is a string limitation when we execute application from command line / terminal which depends on the OS.
But if we use the Java ProcessBuilder to execute application, is there any maximum string length to be passed as argument in the java ProcessBuilder ?

   ProcessBuilder pb = new ProcessBuilder("myCommand", "myArg1", "myArg2");

Thanks


Solution

  • If you look at ProcessBuilder source code the process creation is delegated to a OS specific java.lang.ProcessImpl.

    For instance the Windows version of ProcessImpl calls CreateProcess in the Win API, passing the commandline string. The documentation for parameter lpCommandLinestates: "The maximum length of this string is 32,768 characters".

    So yes there will be OS specific length limitations, based on the OS function to create the process.