A function is called in Batch Script by using the call command. Following is the syntax.
Following example shows how a function can be called from the main program.
@echo off SETLOCAL CALL :Display EXIT /B %ERRORLEVEL% :Display SET /A index=2 echo The value of index is %index% EXIT /B 0
One key thing to note when defining the main program is to ensure that the statement EXIT /B %ERRORLEVEL% is put in the main program to separate the code of the main program from the function.
The above command produces the following output.
The value of index is 2