maximum command line parameter length? 命令行参数可以有多长?
作者:半瓶墨水 链接:http://www.2maomao.com/blog/maximum-command-line-parameter-length/
同事问了一个相关的问题,以前猜测是1024,验证了一下,居然是8196
#how long can a command line parameter have?
#
# Directly answer is 8196 on Window7(not sure about other platform)
#
#It’s easy to write a script to repro it:
#1. In one script, output the parameter it got, say script#1
#2. In another script, recursively execute script#1 and increase parameter step by step,
# capture the output, see if you have the same with the parameter you give
#
# Usage: python test2.py
# then you got the result
# (if it's 10000, then adjust "end" variable below)
#
#— test.py —
import sys
print sys.argv[1]
#
# Directly answer is 8196 on Window7(not sure about other platform)
#
#It’s easy to write a script to repro it:
#1. In one script, output the parameter it got, say script#1
#2. In another script, recursively execute script#1 and increase parameter step by step,
# capture the output, see if you have the same with the parameter you give
#
# Usage: python test2.py
# then you got the result
# (if it's 10000, then adjust "end" variable below)
#
#— test.py —
import sys
print sys.argv[1]
#— test2.py —
import sys,os
param = 'a'
start = 0
end = 10000
while start < end: #binary search to speed up
mid = (start + end) / 2
param = 'a' * mid
cmdline = 'test.py ' + param
out = os.popen(cmdline).read().rstrip()
if param == out:
start = mid + 1
else:
end = mid - 1
print len(param)
print "\nMax Command Line Length=", start
#What I got on Window7 is: 8153
# considering cmd.exe starts with "C:\\Windows\\system32\\cmd.exe /c test.py "
# then the maximum is about 8196
共 2 条评论
发表评论
Additional comments powered by BackType



这些我都看不懂啊
你的水平可真高啊 呵呵