|
Showing:
CALL Commands
CALL is much like CALLs in high level languages. It causes the name of the CALLing batch file and the location in the file to be saved (by COMMAND.COM) so that execution can be resumed at the next line in the file, when the CALLed batch file terminates. Since each CALL consumes some memory until it is cleared by the return of the CALLed program, there is a finite limit to the number of CALLs that can be nested.
CALL lets you invoke a batch file from a batch file without loosing your place in the first one. The two batch files may be different files, or the same file. When they are the same, the effect is that of recursion. CALL causes COMMAND.COM to save the name and file pointer for the current file before invoking the second one and to reenter the original file at the location indicated by the file pointer on its termination. CALL can also be used to invoke executables, though COMMAND.COM doesn't seem to do anything different when you do. However, there is a certain flexibility in using CALL to invoke executables: you can later replace the .EXE file with a same named .BAT file to change the action. It is also safer to use CALL when you don't know for sure that the program you have been told just the name of is in fact a .COM or .EXE, rather than . .BAT file. CALL also is useful in FOR loops both in batch files and from the command line to prevent the loop from terminating prematurely when the action is a batch file.
*
CALL FileName
[Arguments] |
[Constants] |
[Return Type] |
[Script Example]
|
Arguments
|
FileName Path and name of an EXE, BAT, CMD, COM file to execute then return.
|
|
Script Example
|
|
Unless otherwise noted, this code is licensed according to the terms and conditions listed
here. |
@ECHO OFF
ECHO ECHO This is the Second Script > C:\FIRST.BAT
ECHO ECHO This is the Thrid Script > C:\SECOND.BAT
ECHO This is the First Script
CALL C:\FIRST.BAT
ECHO This is the First Script again
CALL C:\SECOND.BAT
ECHO This is the First Script again
DEL C:\FIRST.BAT
DEL C:\SECOND.BAT |
* This text may contain reprinted material from the
Microsoft
.
|