call
- help call
Output:
Calls one batch program from another.
CALL [drive:][path]filename [batch-parameters]
batch-parameters Specifies any command-line information required by the
batch program.
If Command Extensions are enabled CALL changes as follows:
CALL command now accepts labels as the target of the CALL. The syntax
is:
CALL :label arguments
A new batch file context is created with the specified arguments and
control is passed to the statement after the label specified. You must
"exit" twice by reaching the end of the batch script file twice. The
first time you read the end, control will return to just after the CALL
statement. The second time will exit the batch script. Type GOTO /?
for a description of the GOTO :EOF extension that will allow you to
"return" from a batch script.
In addition, expansion of batch script argument references (%0, %1,
etc.) have been changed as follows:
%* in a batch script refers to all the arguments (e.g. %1 %2 %3
%4 %5 ...)
Substitution of batch parameters (%n) has been enhanced. You can
now use the following optional syntax:
%~1 - expands %1 removing any surrounding quotes (")
%~f1 - expands %1 to a fully qualified path name
%~d1 - expands %1 to a drive letter only
%~p1 - expands %1 to a path only
%~n1 - expands %1 to a file name only
%~x1 - expands %1 to a file extension only
%~s1 - expanded path contains short names only
%~a1 - expands %1 to file attributes
%~t1 - expands %1 to date/time of file
%~z1 - expands %1 to size of file
%~$PATH:1 - searches the directories listed in the PATH
environment variable and expands %1 to the fully
qualified name of the first one found. If the
environment variable name is not defined or the
file is not found by the search, then this
modifier expands to the empty string
The modifiers can be combined to get compound results:
%~dp1 - expands %1 to a drive letter and path only
%~nx1 - expands %1 to a file name and extension only
%~dp$PATH:1 - searches the directories listed in the PATH
environment variable for %1 and expands to the
drive letter and path of the first one found.
%~ftza1 - expands %1 to a DIR like output line
In the above examples %1 and PATH can be replaced by other
valid values. The %~ syntax is terminated by a valid argument
number. The %~ modifiers may not be used with %*
Return Code: 1
example
_call1.bat
@echo call1
call _call2.bat
call :_test
@echo call1_1
:_test
@echo call1_2
goto:eof
@echo call1_3
_call2.bat
@echo call2
exit /b
@echo call2_1
To return to the caller, use goto :EOF or exit /B
call1
c:\example>call _call2.bat
call2
c:\example>exit /b
c:\example>call :_test
call1_2
c:\example>goto:eof
call1_1
call1_2
c:\example>goto:eof
Expansion
_call3.bat
rem %%0 %0
copy C:\Windows\System32\find.exe find.exe
call :ParameterCheck "find.exe"
call :PATHCheck "find.exe"
set ORI=C:\Windows
call :ORICheck "explorer.exe"
@goto :EOF
:ParameterCheck
@echo %%0 %0
@echo %%1 %1
@echo %%~1 %~1
@echo %%~f1 %~f1
@echo %%~d1 %~d1
@echo %%~p1 %~p1
@echo %%~n1 %~n1
@echo %%~x1 %~x1
@echo %%~s1 %~s1
@echo %%~a1 %~a1
@echo %%~t1 %~t1
@echo %%~z1 %~z1
@echo %%~dp1 %~dp1
@echo %%~nx1 %~nx1
@echo %%~ftza1 %~ftza1
@goto :EOF
:PATHCheck
@echo %%~f1 %~f1
@echo %%~$PATH:1 %~$PATH:1
@echo %%~dp$PATH:1 %~dp$PATH:1
@goto :EOF
:ORICheck
@echo %%~f1 %~f1
@echo %%~$ORI:1 %~$ORI:1
@echo %%~dp$ORI:1 %~dp$ORI:1
@goto :EOF
Optional syntax
c:\example>rem %0 .\_call3.bat
c:\example>copy C:\Windows\System32\find.exe find.exe
1 file(s) copied.
c:\example>call :ParameterCheck "find.exe"
%0 :ParameterCheck
%1 "find.exe"
%~1 find.exe
%~f1 c:\example\find.exe
%~d1 c:
%~p1 \example\
%~n1 find
%~x1 .exe
%~s1 c:\example\find.exe
%~a1 --a--------
%~t1 07/07/2022 04:48 PM
%~z1 17920
%~dp1 c:\example\
%~nx1 find.exe
%~ftza1 --a-------- 07/07/2022 04:48 PM 17920 c:\example\find.exe
c:\example>call :PATHCheck "find.exe"
%~f1 c:\example\find.exe
%~$PATH:1 C:\Windows\System32\find.exe
%~dp$PATH:1 C:\Windows\System32\
c:\example>set ORI=C:\Windows
c:\example>call :ORICheck "explorer.exe"
%~f1 c:\example\explorer.exe
%~$ORI:1 C:\Windows\explorer.exe
%~dp$ORI:1 C:\Windows\
Batch parameters
_call4.bat
call :test a,b,c
call :test "a b" c
call :test a "b,c",d
@goto:eof
:test
@echo %%1[%1] %%2[%2] %%3[%3]
Batch parameters separators is comma and space. cmd
c:\example>call :test a,b,c
%1[a] %2[b] %3[c]
c:\example>call :test "a b" c
%1["a b"] %2[c] %3[]
c:\example>call :test a "b,c",d
%1[a] %2["b,c"] %3[d]