Backquoted parameters used in GoSub don't pass string as a single parameter

I'm not sure if this is a bug or WAD, but it appears that backquoted parameter strings passed to subroutines do not get treated as a single parameter with embedded spaces as they do when calling a separate batch/btm file.

I was able to get around the issue by making the last parameter for the subroutine "hungry" with a trailing "*".

Below is a a simple example which demonstrates the situation. If this is WAD, it might be worth mentioning in the help file entry for GoSub.

Thanks,
-Michael


[C:\Batfile]type TestParameters.btm

@echo off

GoSub TestSubParams 1stParam "2nd Param" `3rd Param`
call TestBTMParams.btm 1stParam "2nd Param" `3rd Param`

quit


:: ========================================================
::
:TestSubParams [p1,p2,p3]
::
:: ========================================================

echo.
echo --- SubRoutine
echo --------- P1: %p1
echo --------- P1: %p2
echo --------- P3: %p3
return

[C:\Batfile]type TestBTMParams.btm

@echo off

echo.
echo --- Called BTM
echo --------- P1: %1
echo --------- P1: %2
echo --------- P3: %3

quit

[C:\Batfile]TestParameters.btm

--- SubRoutine
--------- P1: 1stParam
--------- P1: "2nd Param"
--------- P3: 3rd

--- Called BTM
--------- P1: 1stParam
--------- P1: "2nd Param"
--------- P3: 3rd Param

[C:\Batfile]
 

rconn

Administrator
Staff member
May 14, 2008
11,947
133
WAD. The single back quotes are removed by the parser before the GOSUB command is called. (They are not removed by CALL, because the parser assumes whoever is the target of the CALL will deal with quoting.)

Change your GOSUB command to escape the back quotes so they won't be removed during preprocessing:

Code:
GoSub TestSubParams 1stParam "2nd Param" ^`3rd Param^`
 
Perfect. Thanks for the quick response. Now that I understand how it works I see that escaping the backquotes will let me pass spaces in any parameter, not just not just the last one.