CALL: Calls one batch program from another.


... "CALL" Excerpt from Microsoft Windows Help
... The examples for the command "CALL"
... Important information, tips for the "CALL" command

The command: "CALL" is on Windows 11, 10, .. available

"CALL" Excerpt from Microsoft Windows Help

Microsoft Windows [Version 10.0.19045.3693]
(c) Copyright 1985-2023 Microsoft Corp.

C:\\WINDOWS>

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 %*

The examples for the command "CALL"

The `CALL` command in the Windows Command Prompt is used to start the execution of another batch script within a batch script. Here are some examples with comments: Example 1: Simple call to another batch script:

CALL other_script.bat

Description: This command calls the batch script `other_script.bat`. The `CALL` command is used to ensure that control returns to the original script after the called script completes. Example 2: Passing parameters to the called script:

CALL other_script.bat Parameter1 Parameter2

Description: Here the parameters `Parameter1` and `Parameter2` are passed to the called batch script. Within `other_script.bat` these parameters can be retrieved with `%1`, `%2`, etc. Example 3: Using `%*` for all parameters passed:

CALL other_script.bat %*

Description:* `%` represents all parameters passed. This command calls `other_script.bat` and passes it all the parameters passed to the original script. Example 4: Check the return value of the called script:

CALL other_script.bat
IF ERRORLEVEL 1 (
    ECHO The script called returned an error.
) ELSE (
    ECHO The called script was executed successfully.
)

Description: The called batch script `other_script.bat` is executed here. Then `ERRORLEVEL` is used to check whether the script returned an error. Example 5: Using `GOTO` after calling:

CALL other_script.bat
GOTO Continue
:Continue
ECHO The script was called successfully.

Description: Here the batch script `other_script.bat` is called, and after the call, execution is redirected to the `Continue` label. The `CALL` command is particularly useful when you want to call another script from a batch script and want to ensure that execution returns to the original script. This is important to continue the original script after calling the other script.

Important information, tips for the "CALL" command

Yes, there are some important points and considerations that you should keep in mind when using the `CALL` command in the Windows Command Prompt: 1. Use with Batch Scripts: The `CALL` command is typically used to call another batch script within a batch script. Note that it may not be necessary when running other file types. 2. Check return value: If the called batch script returns a return value, you can check it with `ERRORLEVEL`. Note that `ERRORLEVEL` only reflects the return value of the most recently executed command.

   CALL other_script.bat
   IF ERRORLEVEL 1 (
       ECHO The script called returned an error.
   ) ELSE (
       ECHO The called script was executed successfully.
   )
   
3. Correct use of parameters: Pay attention to the correct use of parameters when passing parameters to the called batch script. The parameters can be retrieved in the called script with `%1`, `%2`, etc.

   CALL other_script.bat Parameter1 Parameter2
   
4. Syntax and spaces: Make sure that the syntax is correct and there are no unnecessary spaces. This can lead to errors. 5. Security Considerations: When using `CALL` in scripts that contain parameters, it is important to ensure that the parameters passed are properly validated and processed to minimize security risks. 6. Monitoring and logging: When developing batch scripts that call other scripts, it is often advisable to use monitoring and logging methods to monitor execution and possible errors. 7. Avoid Infinite Loops: Be careful not to accidentally create infinite loops by calling batch scripts in a loop. This could result in scripts calling themselves over and over again. 8. Version-Specific Differences: Note that the functionality of the `CALL` command may vary depending on the version of Windows. It is advisable to consult the documentation for your specific version of Windows. Take these considerations into account to ensure that using `CALL` in your batch scripts is done correctly and safely.


Deutsch
English
Español
Français
Italiano
日本語 (Nihongo)
한국어 (Hangugeo)
汉语 (Hànyǔ)
Türkçe
Português
Português
Svenska
Norsk
Dansk
Suomi
Nederlands
Polski









Windows-10


... Windows 10 FAQ
... Windows 10 How To


Windows 10 How To


... Windows 11 How To
... Windows 10 FAQ



The command CALL - Calls one batch program from another.

HTTP: ... console/en/006.htm
0.109
12243

Windows 10 geht zu früh in den Ruhezustand!

Aktivieren vom Ransomware Schutz unter Windows 10 kostenlos!

Windows 10/11: shell:fonts!

In Windows 10 den integrierten PDF Drucker Treiber installieren!

Windows 10 / 11 control system (classic panel)!

How do I change the logon screen background from Windows 10/11?



(0)