Home > Commands A-M > Batch Ca-Cg


Description | Syntax | Parameters | Switches | Related | Notes | Examples | Errorlevels | Availability

Calls one batch program from another without causing the first batch program to stop (aka GOSUB).



CALL [drive:][path]filename [batch-parameters]

CALL :label [parameters]

drive: (v3.30 Win95 NT3.5)
Specifies the drive location of batch program you want to call.
:label (NT3.5)
Jump to a label somewhere within the current batch file.
When you jump to a subroutine with CALL, all statements after the label are treated like a separate batch file. When the end of the batch is reached, it will exit and control will return back to just after the position where you used CALL.
You can therefore reach the end of the batch script file more than once.
Don't forget you can also pass command-line arguments to the :label and refer to these just like the parameters passed to a separate batch file.
parameters (NT3.5)
Any command-line arguments.
If Command Extensions are disabled, the CALL command will not accept batch labels.
path (v3.30 Win95 NT3.5)
Specifies the path location of batch program you want to call.
filename (v3.30 Win95 NT3.5)
Specifies the name of the batch program you want to call. Filename must have a .BAT extension.
batch-parameters (v3.30 Win95 NT3.5)
Specifies any command-line information required by the batch program.

/? (NTXP)
Display help.


CMD - can be used to call a subsequent batch and ALWAYS return even if errors occur.
GOTO - jump to a label or GOTO :eof
START - Start a separate window to run a specified program or command
Equivalent Linux BASH commands:
builtin - Run a shell builtin
chroot - Run a command with a different root directory
.period - Run commands from a file

Using batch-parameters

Batch-parameters can contain any information that you can pass to a batch program, including switches, filenames, the replaceable parameters (%0) %1 through %9, and environment variables such as %baud%.

Expansion of batch script argument references (%0, %1, ..., %9), beginning with NT2000 have been changed:

Combinations are allowed:

The %~ syntax is terminated by a valid argument number.

Using pipes and redirection symbols

Do not use pipes ('|') and redirection symbols ('<<','<','>', and '>>') with the CALL command.

Making a recursive call

You can create a batch program that calls itself; however, you must provide an exit command. Otherwise, the parent and child batch programs can loop endlessly.


To run the CHECKNEW.BAT program from another batch program, include this command in the parent batch program:


Suppose the parent batch program accepts two replaceable parameters and you want it to pass those parameters to CHECKNEW.BAT. You can use the command in the parent batch program:


Passing parameters to a label:

     CALL :s_staff SMITH 100
     GOTO :eof

     ECHO Name is %1
     ECHO Rate is %2
     GOTO :eof


Returning parameters:

     CALL :s_calc 200 100
     ECHO %v_return%
     GOTO :eof

     SET v_sum=0
     IF %1 GTR %2 SET v_sum=5
     ENDLOCAL & SET v_return=%v_sum%
     GOTO :eof




v3.30 v3.3A v3.3R v3.3T v3.31 v3.40 v4.0 v4.01 v4.01A v5.0 v5.0A v5.00.02 v5.001A v5.01 v5.02 v6.0 v6.10 v6.2 v6.21 v6.22 v6.23 v7.00 v7.0R1 v7.10 v8.00
Win95 Win98 WinME
Windows NT
NT3.5 NT4 NT2000 NTXP NT2003