Table of Contents

Dos - Call (Subroutine, function)

About

The command “call” calls:

The START command create a new cmd.exe process with then a new context (new environment variable) (with the /b option it will not open a new window)

Syntax

Call a file

CALL filePathName arguments

where:

Call a label

The CALL command now accepts labels as the target of the CALL.

CALL :label arguments

:label
REM exit the subroutine 
goto :EOF

where:

ie How to create a DOS function ? (known also as a subroutine)

Example

Label

@echo off

call :subroutine %*
exit /b %ERRORLEVEL%

:subroutine
echo Hello %*
goto :eof

:subroutine2
echo We will never see this

On the console:

echo.bat Nico
Hello Nico