Home
> Commands A-M
> Batch Ca-Cg
CALL
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).
Syntax
CALL
/?
CALL
[drive:][path]filename
[batch-parameters]
CALL
:label
[parameters]
Parameters
- drive:
(v3.30
Win95
NT3.1)
- 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.1)
- Specifies the path location of batch program you want to
call.
- filename
(v3.30
Win95
NT3.1)
- Specifies the name of the batch program you want to call.
Filename must have a .BAT extension.
- batch-parameters
(v3.30
Win95
NT3.1)
- Specifies any command-line information required by the batch
program.
Switches
- /?
(NTXP)
- Display help.
Related
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
Notes
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:
- %* expands to all the arguments (%1, %2, ..., %9) The %~ modifiers may not be used with %*
- %~ expands removing any surrounding quotes ("), ie. %~1
- %~a expands to file attributes, ie. %~a2
- %~d expands to a drive letter only, ie. %~d1
- %~f expands to a fully qualified path name, ie. %~f3
- %~n expands to a file name only, ie. %~n2
- %~p expands to a path only, ie. %~p1
- %~s expanded path contains short names only, ie. %~s2
- %~t expands to date/time of file, ie. %~t1
- %~x expands to a file extension only, ie. %~x3
- %~z expands to size of file, ie. %~z1
- %~$PATH: expands to full qualified name of first file found by searching the
%PATH% directories, ie. %~$PATH:1 OR expands to the empty string (environment variable not defined or file not found)
Combinations are allowed:
- %~dp1 expands %1 to a drive letter and path only
- %~nx3 expands %3 to a file name and extension only
- %~dp$PATH:2 searches the directories listed in the
%PATH% environment variable for %2 and expands to the drive letter and path of the first one found
- %~ftza1 expands %1 to a DIR like output line
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.
Examples
To run the CHECKNEW.BAT program from another batch program,
include this command in the parent batch program:
CALL CHECKNEW
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:
CALL CHECKNEW %1 %2
Passing parameters to a label:
@ECHO OFF
SETLOCAL
CALL :s_staff SMITH 100
GOTO :eof
:s_staff
SETLOCAL
ECHO Name is %1
ECHO Rate is %2
GOTO :eof
:eof
Returning parameters:
@ECHO OFF
SETLOCAL
CALL :s_calc 200 100
ECHO %v_return%
GOTO :eof
:s_calc
SETLOCAL
SET v_sum=0
IF %1 GTR %2 SET v_sum=5
ENDLOCAL & SET v_return=%v_sum%
GOTO :eof
:eof
Errorlevels
none.
Availability
- Internal
-
- DOS
-
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
- Windows
-
Win95
Win98
WinME
- Windows NT
-
NT3.1
NT3.5
NT3.51
NT4
NT2000
NTXP
NT2003
Last Updated: 2006/12/01
Direct corrections or suggestions to:
Rick Lively