Pedro Sales
Pedro Sales

Reputation: 553

execute a call in batch file to a lable with variable

It should be a simple thing, but I'm not getting it

I want to do a call inside a batch file to a label using a variable as a parameter, something like this:

echo off
set TEST=message text
call :MESSAGE %TEST% more text
:MESSAGE
echo %1

what I get is this:

C:\>echo off
message
ECHO is off.

Upvotes: 0

Views: 104

Answers (2)

Pedro Sales
Pedro Sales

Reputation: 553

use %* instead of %1 ... simple as that!

Upvotes: 0

MC ND
MC ND

Reputation: 70923

:message is a label. There is no boundary to avoid the execution to enter the code after it, but this time the code is reached without a parameter to echo and from here the ECHO off

@echo off
  set TEST=message text
  call :MESSAGE %TEST% more text
  goto :eof

:MESSAGE
  echo %1

Now the goto :eof (or exit /b to leave the batch file or exit to close the console) avoid the execution to continue into the code after the label

Upvotes: 2

Related Questions