> Commands A-M
> Batch Ca-Cg
Calls one batch program from another without causing the first
batch program to stop (aka GOSUB).
- Specifies the drive location of batch program you want to
- 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.
- Any command-line arguments.
- If Command Extensions are disabled, the CALL command will
not accept batch labels.
- Specifies the path location of batch program you want to
- Specifies the name of the batch program you want to call.
Filename must have a .BAT extension.
- Specifies any command-line information required by the batch
- 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
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
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
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
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
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
CALL CHECKNEW %1 %2
Passing parameters to a label:
CALL :s_staff SMITH 100
ECHO Name is %1
ECHO Rate is %2
CALL :s_calc 200 100
IF %1 GTR %2 SET v_sum=5
ENDLOCAL & SET v_return=%v_sum%
- Windows NT