Search code examples
windowsstringdostruncatearguments

string gets truncated when passing it as parameter from bat if it has more than 6 spaces


Platform: Windows 7, Windows XP Software: DOS

I know about command line length limitation but I never experienced something like this". I have doskey command passing parameters/arguments to vbs script and I have determined that if I try to pass string with spaces which contains more than 6 spaces - everything beyond 6th space gets truncated. Is this known limitation??

Here is how doskey looks like:

set scripts=C:\Windows\Scripts\    
doskey tt=@echo off $t cscript //NoLogo %scripts%tt.vbs %scripts% $1 $2 $t @echo on

Now you can open batch and test it by entering simple string like:

tt + "1 2 3 4 5 6 7 8 9"

And the result will be:

1 2 3 4 5 6

Length doesn't matter, I can test it with any other string and it will be truncated after 6th space.

Does anybody have idea or knows the solution?


Solution

  • I actually have no explanation, but a workaround:

    Use simple quotes : it seems double quotes are not considered by doskey (or more probably parsed by cmd) and thus it uses spaces to split values into args.

    I think the 6th space limitation comes from that doskey stops at 9 args (%1-%9) and you reach the limit. Your 6 numbers, the + sign, the %scripts% args and the script itself make for 9