单个字符串参数的最大大小限制为131072.它与python无关:
~$/bin/echo "$(printf "%*s" 131071 "a")">/dev/null
~$/bin/echo "$(printf "%*s" 131072 "a")">/dev/null
bash: /bin/echo: Argument list too long
实际上是MAX_ARG_STRLEN决定单个字符串的最大大小:
And as additional limit since 2.6.23, one argument must not be longer than MAX_ARG_STRLEN (131072).
This might become relevant if you generate a long call like “sh -c ‘generated with long arguments'”.
(pointed out by Xan Lopez and Ralf Wildenhues)
请参阅this discussion of ARG_MAX,“参数数量和一个参数的最大长度”和unix.stackexchange上的this question.
你可以在binfmts.h中看到它:
/*
* These are the maximum length and maximum number of strings passed to the
* execve() system call. MAX_ARG_STRLEN is essentially random but serves to
* prevent the kernel from being unduly impacted by misaddressed pointers.
* MAX_ARG_STRINGS is chosen to fit in a signed 32-bit integer.
*/
#define MAX_ARG_STRLEN (PAGE_SIZE * 32)
#define MAX_ARG_STRINGS 0x7FFFFFFF
~$echo $(( $(getconf PAGE_SIZE)*32 ))
131072
您可以传递多个长度为131071的字符串:
subprocess.check_call(['echo', "a"*131071,"b"*131071], executable='/bin/bash',stdout=open("/dev/null","w"))
但是单个字符串arg不能超过131071个字节.