By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

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.


[C:\Batfile]type TestParameters.btm

@echo off

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


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

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

[C:\Batfile]type TestBTMParams.btm

@echo off

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



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

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

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:

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.

Similar threads