Home > other >  Batch how to pass a parameter with space to function?
Batch how to pass a parameter with space to function?

Time:10-20

how to pass a parameter with space or ; to function?

call :MyFunct "arg1" "arg2 arg2";"arg2"

:MyFunct

echo %~2

I would like to retrieve from %~1 "arg2 arg2";"arg2" but do not know how to do

CodePudding user response:

For your sample "arg1" "arg2 arg2";"arg2" the arguments are

arg1="arg1"
arg2="arg2 arg2"
arg3="arg2"

That's simply the rule of cmd.exe, any unquoted delimiter in the arguments splits arguments, delimiters are <space>;,=

If you want a different behavior, you need to write your own parsing function on the basis of %* or even better on the bullet proof argument reading

  • Related