Batch Script Functions with Return Values
Functions with Return Values
In Batch Script, functions can work with return values simply by passing the names of the variables that will contain the return values when a call is made to the function.
Call :function_name value1, value2… valuen
Return values are set in the function using the set
command and the tilde character (~
) along with the parameter position number.
Example
The following example shows how a function can be called with return values.
Example of Functions with return values
@echo off
SETLOCAL
CALL :SetValue value1,value2
echo %value1%
echo %value2%
EXIT /B %ERRORLEVEL%
:SetValue
set "%~1=5"
set "%~2=10"
EXIT /B 0
5
10