Dos - Call (Subroutine, function)

Card Puncher Data Processing


The command “call” calls:

  • one batch script passing the (variable|execution) context (the environment variable)
  • a label (ie function)

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)


Call a file

CALL filePathName arguments


Call a label

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

CALL :label arguments

REM exit the subroutine 
goto :EOF


  • goto :eof exit the subroutine

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



@echo off

call :subroutine %*
exit /b %ERRORLEVEL%

echo Hello %*
goto :eof

echo We will never see this

On the console:

echo.bat Nico
Hello Nico

Discover More
Card Puncher Data Processing
Dos - (Batch) Script

The batch script is a text file with the extension .bat or .cmd that is interpreted by a batch interpreter. You can call a batch script by : writing its name in the source script: The script execution...
Card Puncher Data Processing
Dos - Command

A command is: a Dos command (See below). of an utility. The DOS command are extended with management tools located in C:\Windows\System32...
Card Puncher Data Processing
Dos - Command line (Argument|Parameter)

Command line arguments for DOS are passed to: the batch script through the cmd or call command: the function (subroutine) through the call command: variablesIf Defined Variable statement “”...
Card Puncher Data Processing
Dos - Control Flow

The flow in DOS can be controlled via: Labels that can be called with the goto (inside the script) or call (outside the script) FOR runs a specified command for each file in a set of files
Card Puncher Data Processing
Dos - Label (Line)

statement in DOS. A label is a place-holder in a batch script “”label The label must be at the beginning of a line with a colon. It can be called via: the goto command inside the script the...
Card Puncher Data Processing
How to create a DOS function ? (known also as a subroutine)

functions in dos are: created and named with a label called with the CALL command creating a subroutine exited with the goto command where: arguments are the argument of the subroutine goto...

Share this page:
Follow us:
Task Runner