在Windows中,命令提示符 (cmd. exe) 命令行字符串是有长度限制的,本文帮助你了解命令行中的字符串长度限制,以免你的批处理脚本踩坑。
(以下在Win10环境测试过)
可在命令提示符处使用的字符串的最大长度为 8191 个字符。
此限制适用于:
如果使用命令提示符运行批处理文件,此限制也适用于批处理文件
set astr=teststring1teststring2teststring3teststring4teststring5teststring6teststring7teststring8teststring9teststring10teststring11teststring12teststring13teststring14teststring15teststring16teststring17teststring18teststring19teststring20teststring21teststring22teststring23teststring24teststring25teststring26teststring27teststring28teststring29teststring30teststring31teststring32teststring33teststring34teststring35teststring36teststring37teststring38teststring39teststring40teststring41teststring42teststring43teststring44teststring45teststring46teststring47teststring48teststring49teststring50teststring51teststring52teststring53teststring54teststring55teststring56teststring57teststring58teststring59teststring60teststring61teststring62teststring63teststring64teststring65teststring66teststring67teststring68teststring69teststring70teststring71teststring72teststring73teststring74teststring75teststring76teststring77teststring78teststring79teststring80teststring81teststring82teststring83teststring84teststring85teststring86teststring87teststring88teststring89teststring90teststring91teststring92teststring93teststring94teststring95teststring96teststring97teststring98teststring99teststring100teststring101teststring102teststring103teststring104teststring105teststring106teststring107teststring108teststring109teststring110teststring111teststring112teststring113teststring114teststring115teststring116teststring117teststring118teststring119teststring120teststring121teststring122teststring123teststring124teststring125teststring126teststring127teststring128teststring129teststring130teststring131teststring132teststring133teststring134teststring135teststring136teststring137teststring138teststring139teststring140teststring141teststring142teststring143teststring144teststring145teststring146teststring147teststring148teststring149teststring150teststring151teststring152teststring153teststring154teststring155teststring156teststring157teststring158teststring159teststring160teststring161teststring162teststring163teststring164teststring165teststring166teststring167teststring168teststring169teststring170teststring171teststring172teststring173teststring174teststring175teststring176teststring177teststring178teststring179teststring180teststring181teststring182teststring183teststring184teststring185teststring186teststring187teststring188teststring189teststring190teststring191teststring192teststring193teststring194teststring195teststring196teststring197teststring198teststring199teststring200teststring201teststring202teststring203teststring204teststring205teststring206teststring207teststring208teststring209teststring210teststring211teststring212teststring213teststring214teststring215teststring216teststring217teststring218teststring219teststring220teststring221teststring222teststring223teststring224teststring225teststring226teststring227teststring228teststring229teststring230teststring231teststring232teststring233teststring234teststring235teststring236teststring237teststring238teststring239teststring240teststring241teststring242teststring243teststring244teststring245teststring246teststring247teststring248teststring249teststring250teststring251teststring252teststring253teststring254teststring255teststring256teststring257teststring258teststring259teststring260teststring261teststring262teststring263teststring264teststring265teststring266teststring267teststring268teststring269teststring270teststring271teststring272teststring273teststring274teststring275teststring276teststring277teststring278teststring279teststring280teststring281teststring282teststring283teststring284teststring285teststring286teststring287teststring288teststring289teststring290teststring291teststring292teststring293teststring294teststring295teststring296teststring297teststring298teststring299teststring300teststring301teststring302teststring303teststring304teststring305teststring306teststring307teststring308teststring309teststring310teststring311teststring312teststring313teststring314teststring315teststring316teststring317teststring318teststring319teststring320teststring321teststring322teststring323teststring324teststring325teststring326teststring327teststring328teststring329teststring330teststring331teststring332teststring333teststring334teststring335teststring336teststring337teststring338teststring339teststring340teststring341teststring342teststring343teststring344teststring345teststring346teststring347teststring348teststring349teststring350teststring351teststring352teststring353teststring354teststring355teststring356teststring357teststring358teststring359teststring360teststring361teststring362teststring363teststring364teststring365teststring366teststring367teststring368teststring369teststring370teststring371teststring372teststring373teststring374teststring375teststring376teststring377teststring378teststring379teststring380teststring381teststring382teststring383teststring384teststring385teststring386teststring387teststring388teststring389teststring390teststring391teststring392teststring393teststring394teststring395teststring396teststring397teststring398teststring399teststring400teststring401teststring402teststring403teststring404teststring405teststring406teststring407teststring408teststring409teststring410teststring411teststring412teststring413teststring414teststring415teststring416teststring417teststring418teststring419teststring420teststring421teststring422teststring423teststring424teststring425teststring426teststring427teststring428teststring429teststring430teststring431teststring432teststring433teststring434teststring435teststring436teststring437teststring438teststring439teststring440teststring441teststring442teststring443teststring444teststring445teststring446teststring447teststring448teststring449teststring450teststring451teststring452teststring453teststring454teststring455teststring456teststring457teststring458teststring459teststring460teststring461teststring462teststring463teststring464teststring465teststring466teststring467teststring468teststring469teststring470teststring471teststring472teststring473teststring474teststring475teststring476teststring477teststring478teststring479teststring480teststring481teststring482teststring483teststring484teststring485teststring486teststring487teststring488teststring489teststring490teststring491teststring492teststring493teststring494teststring495teststring496teststring497teststring498teststring499teststring500teststring501teststring502teststring503teststring504teststring505teststring506teststring507teststring508teststring509teststring510teststring511teststring512teststring513teststring514teststring515teststring516teststring517teststring518teststring519teststring520teststring521teststring522teststring523teststring524teststring525teststring526teststring527teststring528teststring529teststring530teststring531teststring532teststring533teststring534teststring535teststring536teststring537teststring538teststring539teststring540teststring541teststring542teststring543teststring544teststring545teststring546teststring547teststring548teststring549teststring550teststring551teststring552teststring553teststring554teststring555teststring556teststring557teststring558teststring559teststring560teststring561teststring562teststring563teststring564teststring565teststring566teststring567teststring568teststring569teststring570teststring571teststring572teststring573teststring574teststring575teststring576teststring577teststring578teststring579teststring580teststring581teststring582teststring583teststring584teststring585teststring586teststring587teststring588teststring589teststring590teststring591teststring592teststring593teststring594teststring595teststring596teststring597teststring598teststring599teststring600teststring601teststring602teststring603teststring604teststring605teststring606teststring607teststring608teststring609teststring610teststring611teststring612teststring613teststring614teststring615teststring616teststring617teststring618teststring619teststring620teststring621teststring622teststring623teststring624teststring625teststring626teststring627teststring628teststring629teststring630teststring631teststring632teststring633teststring634teststring635teststring636teststring637teststri
注意:官网说是不能超过8191个,我测试发现,最多8190个,第8191个无法输入,可能是闪烁的光标占了一个字符吧。
@echo off
set astr=teststring1teststring2teststring3teststring4teststring5teststring6teststring7teststring8teststring9teststring10teststring11teststring12teststring13teststring14teststring15teststring16teststring17teststring18teststring19teststring20teststring21teststring22teststring23teststring24teststring25teststring26teststring27teststring28teststring29teststring30teststring31teststring32teststring33teststring34teststring35teststring36teststring37teststring38teststring39teststring40teststring41teststring42teststring43teststring44teststring45teststring46teststring47teststring48teststring49teststring50teststring51teststring52teststring53teststring54teststring55teststring56teststring57teststring58teststring59teststring60teststring61teststring62teststring63teststring64teststring65teststring66teststring67teststring68teststring69teststring70teststring71teststring72teststring73teststring74teststring75teststring76teststring77teststring78teststring79teststring80teststring81teststring82teststring83teststring84teststring85teststring86teststring87teststring88teststring89teststring90teststring91teststring92teststring93teststring94teststring95teststring96teststring97teststring98teststring99teststring100teststring101teststring102teststring103teststring104teststring105teststring106teststring107teststring108teststring109teststring110teststring111teststring112teststring113teststring114teststring115teststring116teststring117teststring118teststring119teststring120teststring121teststring122teststring123teststring124teststring125teststring126teststring127teststring128teststring129teststring130teststring131teststring132teststring133teststring134teststring135teststring136teststring137teststring138teststring139teststring140teststring141teststring142teststring143teststring144teststring145teststring146teststring147teststring148teststring149teststring150teststring151teststring152teststring153teststring154teststring155teststring156teststring157teststring158teststring159teststring160teststring161teststring162teststring163teststring164teststring165teststring166teststring167teststring168teststring169teststring170teststring171teststring172teststring173teststring174teststring175teststring176teststring177teststring178teststring179teststring180teststring181teststring182teststring183teststring184teststring185teststring186teststring187teststring188teststring189teststring190teststring191teststring192teststring193teststring194teststring195teststring196teststring197teststring198teststring199teststring200teststring201teststring202teststring203teststring204teststring205teststring206teststring207teststring208teststring209teststring210teststring211teststring212teststring213teststring214teststring215teststring216teststring217teststring218teststring219teststring220teststring221teststring222teststring223teststring224teststring225teststring226teststring227teststring228teststring229teststring230teststring231teststring232teststring233teststring234teststring235teststring236teststring237teststring238teststring239teststring240teststring241teststring242teststring243teststring244teststring245teststring246teststring247teststring248teststring249teststring250teststring251teststring252teststring253teststring254teststring255teststring256teststring257teststring258teststring259teststring260teststring261teststring262teststring263teststring264teststring265teststring266teststring267teststring268teststring269teststring270teststring271teststring272teststring273teststring274teststring275teststring276teststring277teststring278teststring279teststring280teststring281teststring282teststring283teststring284teststring285teststring286teststring287teststring288teststring289teststring290teststring291teststring292teststring293teststring294teststring295teststring296teststring297teststring298teststring299teststring300teststring301teststring302teststring303teststring304teststring305teststring306teststring307teststring308teststring309teststring310teststring311teststring312teststring313teststring314teststring315teststring316teststring317teststring318teststring319teststring320teststring321teststring322teststring323teststring324teststring325teststring326teststring327teststring328teststring329teststring330teststring331teststring332teststring333teststring334teststring335teststring336teststring337teststring338teststring339teststring340teststring341teststring342teststring343teststring344teststring345teststring346teststring347teststring348teststring349teststring350teststring351teststring352teststring353teststring354teststring355teststring356teststring357teststring358teststring359teststring360teststring361teststring362teststring363teststring364teststring365teststring366teststring367teststring368teststring369teststring370teststring371teststring372teststring373teststring374teststring375teststring376teststring377teststring378teststring379teststring380teststring381teststring382teststring383teststring384teststring385teststring386teststring387teststring388teststring389teststring390teststring391teststring392teststring393teststring394teststring395teststring396teststring397teststring398teststring399teststring400teststring401teststring402teststring403teststring404teststring405teststring406teststring407teststring408teststring409teststring410teststring411teststring412teststring413teststring414teststring415teststring416teststring417teststring418teststring419teststring420teststring421teststring422teststring423teststring424teststring425teststring426teststring427teststring428teststring429teststring430teststring431teststring432teststring433teststring434teststring435teststring436teststring437teststring438teststring439teststring440teststring441teststring442teststring443teststring444teststring445teststring446teststring447teststring448teststring449teststring450teststring451teststring452teststring453teststring454teststring455teststring456teststring457teststring458teststring459teststring460teststring461teststring462teststring463teststring464teststring465teststring466teststring467teststring468teststring469teststring470teststring471teststring472teststring473teststring474teststring475teststring476teststring477teststring478teststring479teststring480teststring481teststring482teststring483teststring484teststring485teststring486teststring487teststring488teststring489teststring490teststring491teststring492teststring493teststring494teststring495teststring496teststring497teststring498teststring499teststring500teststring501teststring502teststring503teststring504teststring505teststring506teststring507teststring508teststring509teststring510teststring511teststring512teststring513teststring514teststring515teststring516teststring517teststring518teststring519teststring520teststring521teststring522teststring523teststring524teststring525teststring526teststring527teststring528teststring529teststring530teststring531teststring532teststring533teststring534teststring535teststring536teststring537teststring538teststring539teststring540teststring541teststring542teststring543teststring544teststring545teststring546teststring547teststring548teststring549teststring550teststring551teststring552teststring553teststring554teststring555teststring556teststring557teststring558teststring559teststring560teststring561teststring562teststring563teststring564teststring565teststring566teststring567teststring568teststring569teststring570teststring571teststring572teststring573teststring574teststring575teststring576teststring577teststring578teststring579teststring580teststring581teststring582teststring583teststring584teststring585teststring586teststring587teststring588teststring589teststring590teststring591teststring592teststring593teststring594teststring595teststring596teststring597teststring598teststring599teststring600teststring601teststring602teststring603teststring604teststring605teststring606teststring607teststring608teststring609teststring610teststring611teststring612teststring613teststring614teststring615teststring616teststring617teststring618teststring619teststring620teststring621teststring622teststring623teststring624teststring625teststring626teststring627teststring628teststring629teststring630teststring631teststring632teststring633teststring634teststring635teststring636teststring637teststring638tests
echo.%astr:~-10%
pause
- 第2行,总共有8200个字符,
set astr=
占9个字符,值占8191个字符,这条命令总长度超过了8191字符???;- 第3行,echo输出astr变量的后10个字符。执行该批处理,会输出
ng638tests
,但是有意思的是,当你把echo off
改为echo on
,再运行该批处理,你会发现,屏幕上显示出来的第2行命令 最后的10个字符串是ststring63
,而且你还会发现,屏幕上第2行共总显示的命令是 8194个字符。
set astr=teststring1teststring2teststring3teststring4teststring5teststring6teststring7teststring8teststring9teststring10teststring11teststring12teststring13teststring14teststring15teststring16teststring17teststring18teststring19teststring20teststring21teststring22teststring23teststring24teststring25teststring26teststring27teststring28teststring29teststring30teststring31teststring32teststring33teststring34teststring35teststring36teststring37teststring38teststring39teststring40teststring41teststring42teststring43teststring44teststring45teststring46teststring47teststring48teststring49teststring50teststring51teststring52teststring53teststring54teststring55teststring56teststring57teststring58teststring59teststring60teststring61teststring62teststring63teststring64teststring65teststring66teststring67teststring68teststring69teststring70teststring71teststring72teststring73teststring74teststring75teststring76teststring77teststring78teststring79teststring80teststring81teststring82teststring83teststring84teststring85teststring86teststring87teststring88teststring89teststring90teststring91teststring92teststring93teststring94teststring95teststring96teststring97teststring98teststring99teststring100teststring101teststring102teststring103teststring104teststring105teststring106teststring107teststring108teststring109teststring110teststring111teststring112teststring113teststring114teststring115teststring116teststring117teststring118teststring119teststring120teststring121teststring122teststring123teststring124teststring125teststring126teststring127teststring128teststring129teststring130teststring131teststring132teststring133teststring134teststring135teststring136teststring137teststring138teststring139teststring140teststring141teststring142teststring143teststring144teststring145teststring146teststring147teststring148teststring149teststring150teststring151teststring152teststring153teststring154teststring155teststring156teststring157teststring158teststring159teststring160teststring161teststring162teststring163teststring164teststring165teststring166teststring167teststring168teststring169teststring170teststring171teststring172teststring173teststring174teststring175teststring176teststring177teststring178teststring179teststring180teststring181teststring182teststring183teststring184teststring185teststring186teststring187teststring188teststring189teststring190teststring191teststring192teststring193teststring194teststring195teststring196teststring197teststring198teststring199teststring200teststring201teststring202teststring203teststring204teststring205teststring206teststring207teststring208teststring209teststring210teststring211teststring212teststring213teststring214teststring215teststring216teststring217teststring218teststring219teststring220teststring221teststring222teststring223teststring224teststring225teststring226teststring227teststring228teststring229teststring230teststring231teststring232teststring233teststring234teststring235teststring236teststring237teststring238teststring239teststring240teststring241teststring242teststring243teststring244teststring245teststring246teststring247teststring248teststring249teststring250teststring251teststring252teststring253teststring254teststring255teststring256teststring257teststring258teststring259teststring260teststring261teststring262teststring263teststring264teststring265teststring266teststring267teststring268teststring269teststring270teststring271teststring272teststring273teststring274teststring275teststring276teststring277teststring278teststring279teststring280teststring281teststring282teststring283teststring284teststring285teststring286teststring287teststring288teststring289teststring290teststring291teststring292teststring293teststring294teststring295teststring296teststring297teststring298teststring299teststring300teststring301teststring302teststring303teststring304teststring305teststring306teststring307teststring308teststring309teststring310teststring311teststring312teststring313teststring314teststring315teststring316teststring317teststring318teststring319teststring320teststring321teststring322teststring323teststring324teststring325teststring326teststring327teststring328teststring329teststring330teststring331teststring332teststring333teststring334teststring335teststring336teststring337teststring338teststring339teststring340teststring341teststring342teststring343teststring344teststring345teststring346teststring347teststring348teststring349teststring350teststring351teststring352teststring353teststring354teststring355teststring356teststring357teststring358teststring359teststring360teststring361teststring362teststring363teststring364teststring365teststring366teststring367teststring368teststring369teststring370teststring371teststring372teststring373teststring374teststring375teststring376teststring377teststring378teststring379teststring380teststring381teststring382teststring383teststring384teststring385teststring386teststring387teststring388teststring389teststring390teststring391teststring392teststring393teststring394teststring395teststring396teststring397teststring398teststring399teststring400teststring401teststring402teststring403teststring404teststring405teststring406teststring407teststring408teststring409teststring410teststring411teststring412teststring413teststring414teststring415teststring416teststring417teststring418teststring419teststring420teststring421teststring422teststring423teststring424teststring425teststring426teststring427teststring428teststring429teststring430teststring431teststring432teststring433teststring434teststring435teststring436teststring437teststring438teststring439teststring440teststring441teststring442teststring443teststring444teststring445teststring446teststring447teststring448teststring449teststring450teststring451teststring452teststring453teststring454teststring455teststring456teststring457teststring458teststring459teststring460teststring461teststring462teststring463teststring464teststring465teststring466teststring467teststring468teststring469teststring470teststring471teststring472teststring473teststring474teststring475teststring476teststring477teststring478teststring479teststring480teststring481teststring482teststring483teststring484teststring485teststring486teststring487teststring488teststring489teststring490teststring491teststring492teststring493teststring494teststring495teststring496teststring497teststring498teststring499teststring500teststring501teststring502teststring503teststring504teststring505teststring506teststring507teststring508teststring509teststring510teststring511teststring512teststring513teststring514teststring515teststring516teststring517teststring518teststring519teststring520teststring521teststring522teststring523teststring524teststring525teststring526teststring527teststring528teststring529teststring530teststring531teststring532teststring533teststring534teststring535teststring536teststring537teststring538teststring539teststring540teststring541teststring542teststring543teststring544teststring545teststring546teststring547teststring548teststring549teststring550teststring551teststring552teststring553teststring554teststring555teststring556teststring557teststring558teststring559teststring560teststring561teststring562teststring563teststring564teststring565teststring566teststring567teststring568teststring569teststring570teststring571teststring572teststring573teststring574teststring575teststring576teststring577teststring578teststring579teststring580teststring581teststring582teststring583teststring584teststring585teststring586teststring587teststring588teststring589teststring590teststring591teststring592teststring593teststring594teststring595teststring596teststring597teststring598teststring599teststring600teststring601teststring602teststring603teststring604teststring605teststring606teststring607teststring608teststring609teststring610teststring611teststring612teststring613teststring614teststring615teststring616teststring617teststring618teststring619teststring620teststring621teststring622teststring623teststring624teststring625teststring626teststring627teststring628teststring629teststring630teststring631teststring632teststring633teststring634teststring635teststring636teststring637teststri
echo.123456%astr%
- 先使用set命令,给astr变量中存放了8181个字符
- 然后使用echo命令进行输出,
echo.123456
共11个字符,%astr%
替换为实际字符串后,该命令行共有8181+11=8192个字符,运行时报错。但改为echo.12345%astr%
,即去掉一个字符,则正常输出。所以展开变量后的命令行字符串总长度不能超过8191个
@echo off
set astr=teststring1teststring2teststring3teststring4teststring5teststring6teststring7teststring8teststring9teststring10teststring11teststring12teststring13teststring14teststring15teststring16teststring17teststring18teststring19teststring20teststring21teststring22teststring23teststring24teststring25teststring26teststring27teststring28teststring29teststring30teststring31teststring32teststring33teststring34teststring35teststring36teststring37teststring38teststring39teststring40teststring41teststring42teststring43teststring44teststring45teststring46teststring47teststring48teststring49teststring50teststring51teststring52teststring53teststring54teststring55teststring56teststring57teststring58teststring59teststring60teststring61teststring62teststring63teststring64teststring65teststring66teststring67teststring68teststring69teststring70teststring71teststring72teststring73teststring74teststring75teststring76teststring77teststring78teststring79teststring80teststring81teststring82teststring83teststring84teststring85teststring86teststring87teststring88teststring89teststring90teststring91teststring92teststring93teststring94teststring95teststring96teststring97teststring98teststring99teststring100teststring101teststring102teststring103teststring104teststring105teststring106teststring107teststring108teststring109teststring110teststring111teststring112teststring113teststring114teststring115teststring116teststring117teststring118teststring119teststring120teststring121teststring122teststring123teststring124teststring125teststring126teststring127teststring128teststring129teststring130teststring131teststring132teststring133teststring134teststring135teststring136teststring137teststring138teststring139teststring140teststring141teststring142teststring143teststring144teststring145teststring146teststring147teststring148teststring149teststring150teststring151teststring152teststring153teststring154teststring155teststring156teststring157teststring158teststring159teststring160teststring161teststring162teststring163teststring164teststring165teststring166teststring167teststring168teststring169teststring170teststring171teststring172teststring173teststring174teststring175teststring176teststring177teststring178teststring179teststring180teststring181teststring182teststring183teststring184teststring185teststring186teststring187teststring188teststring189teststring190teststring191teststring192teststring193teststring194teststring195teststring196teststring197teststring198teststring199teststring200teststring201teststring202teststring203teststring204teststring205teststring206teststring207teststring208teststring209teststring210teststring211teststring212teststring213teststring214teststring215teststring216teststring217teststring218teststring219teststring220teststring221teststring222teststring223teststring224teststring225teststring226teststring227teststring228teststring229teststring230teststring231teststring232teststring233teststring234teststring235teststring236teststring237teststring238teststring239teststring240teststring241teststring242teststring243teststring244teststring245teststring246teststring247teststring248teststring249teststring250teststring251teststring252teststring253teststring254teststring255teststring256teststring257teststring258teststring259teststring260teststring261teststring262teststring263teststring264teststring265teststring266teststring267teststring268teststring269teststring270teststring271teststring272teststring273teststring274teststring275teststring276teststring277teststring278teststring279teststring280teststring281teststring282teststring283teststring284teststring285teststring286teststring287teststring288teststring289teststring290teststring291teststring292teststring293teststring294teststring295teststring296teststring297teststring298teststring299teststring300teststring301teststring302teststring303teststring304teststring305teststring306teststring307teststring308teststring309teststring310teststring311teststring312teststring313teststring314teststring315teststring316teststring317teststring318teststring319teststring320teststring321teststring322teststring323teststring324teststring325teststring326teststring327teststring328teststring329teststring330teststring331teststring332teststring333teststring334teststring335teststring336teststring337teststring338teststring339teststring340teststring341teststring342teststring343teststring344teststring345teststring346teststring347teststring348teststring349teststring350teststring351teststring352teststring353teststring354teststring355teststring356teststring357teststring358teststring359teststring360teststring361teststring362teststring363teststring364teststring365teststring366teststring367teststring368teststring369teststring370teststring371teststring372teststring373teststring374teststring375teststring376teststring377teststring378teststring379teststring380teststring381teststring382teststring383teststring384teststring385teststring386teststring387teststring388teststring389teststring390teststring391teststring392teststring393teststring394teststring395teststring396teststring397teststring398teststring399teststring400teststring401teststring402teststring403teststring404teststring405teststring406teststring407teststring408teststring409teststring410teststring411teststring412teststring413teststring414teststring415teststring416teststring417teststring418teststring419teststring420teststring421teststring422teststring423teststring424teststring425teststring426teststring427teststring428teststring429teststring430teststring431teststring432teststring433teststring434teststring435teststring436teststring437teststring438teststring439teststring440teststring441teststring442teststring443teststring444teststring445teststring446teststring447teststring448teststring449teststring450teststring451teststring452teststring453teststring454teststring455teststring456teststring457teststring458teststring459teststring460teststring461teststring462teststring463teststring464teststring465teststring466teststring467teststring468teststring469teststring470teststring471teststring472teststring473teststring474teststring475teststring476teststring477teststring478teststring479teststring480teststring481teststring482teststring483teststring484teststring485teststring486teststring487teststring488teststring489teststring490teststring491teststring492teststring493teststring494teststring495teststring496teststring497teststring498teststring499teststring500teststring501teststring502teststring503teststring504teststring505teststring506teststring507teststring508teststring509teststring510teststring511teststring512teststring513teststring514teststring515teststring516teststring517teststring518teststring519teststring520teststring521teststring522teststring523teststring524teststring525teststring526teststring527teststring528teststring529teststring530teststring531teststring532teststring533teststring534teststring535teststring536teststring537teststring538teststring539teststring540teststring541teststring542teststring543teststring544teststring545teststring546teststring547teststring548teststring549teststring550teststring551teststring552teststring553teststring554teststring555teststring556teststring557teststring558teststring559teststring560teststring561teststring562teststring563teststring564teststring565teststring566teststring567teststring568teststring569teststring570teststring571teststring572teststring573teststring574teststring575teststring576teststring577teststring578teststring579teststring580teststring581teststring582teststring583teststring584teststring585teststring586teststring587teststring588teststring589teststring590teststring591teststring592teststring593teststring594teststring595teststring596teststring597teststring598teststring599teststring600teststring601teststring602teststring603teststring604teststring605teststring606teststring607teststring608teststring609teststring610teststring611teststring612teststring613teststring614teststring615teststring616teststring617teststring618teststring619teststring620teststring621teststring622teststring623teststring624teststring625teststring626teststring627teststring628teststring629teststring630teststring631teststring632teststring633teststring634teststring635teststring636teststring637teststri
echo.123456%astr%
pause
- 第2行,set命令给astr变量赋值了8181个字符
- 第3行,
echo.123456
共11个字符,%astr%
替换为实际字符串后,该命令行共有8181+11=8192个字符,运行该批处理文件,闪一下,无任何输出信息。但改为echo.12345%astr%
,即去掉一个字符,再执行该批处理,正常。所以展开变量后的命令行字符串总长度不能超过8191个。
官网也给了示例:command-line-string-limitation
可以结合官网的示例,仔细体会下。
1)set命令,给变量赋值时,变量最多能存放8191个字符。但是命令行长度set
+变量名=
+字符串值
总长度超过了8191个字符;
2)在命令行窗口上,单个命令行最多允许8190个字符(光标占了一个字符);
3)echo命令,最多只能输出8186个字符(echo.
本身占5个字符);
多数情况下,你的脚本可能达不到这些限制,但保不齐哪天会掉到这个坑里,多了解些这些限制总不会有错吧
关于如何应对这些限制,官网也给了解决建议,自行查阅
如何解决限制问题