#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 --- importsys printsys.argv[1]
#--- test2.py --- importsys,os param='a' start=0 end=10000 whilestart<end:#binary search to speed up mid= (start+end) /2 param='a'*mid cmdline='test.py '+param out=os.popen(cmdline).read().rstrip() ifparam==out: start=mid+1 else: end=mid-1 printlen(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