> DOS 中文参考手册 > call

CALL

(call)


从一个批处理程序中调用另一个批处理程序,而不会引起第一个批处理的中止。

CALL [drive:][path]filename [batch-parameters] 

[drive:][path]filename

指定要调用的批处理程序的名字及其存放处。文件名必须用.BAT作扩展名。

batch-parameters 指定批处理程序所需的命令行信息。

如果命令扩展名被启用,CALL 会如下改变:

CALL 命令现在将卷标当作 CALL 的目标接受。语法是:

    CALL:label arguments

一个新的批文件上下文由指定的参数所创建,控制在卷标被指定后传递到语句。您必须通过达到批脚本文件末两次来 "exit" 两次。第一次读到文件末时,控制会回到 CALL 语句的紧后面。第二次会退出批脚本。键入 GOTO /?,参看 GOTO  : EOF  扩展名的描述,此描述允许您从一个批脚本返回。

另外,批脚本文本参数参照(%0、%1、等等)已如下改变:

     批脚本里的 %* 指出所有的参数(如 %1 %2 %3 %4 %5 ...)

     批参数(%n)的替代已被增强。您可以使用以下语法:

         %~1         - 删除引号("),扩充 %1

         %~f1        - 将 %1 扩充到一个完全合格的路径名

         %~d1        - 仅将 %1 扩充到一个驱动器号

         %~p1        - 仅将 %1 扩充到一个路径

         %~n1        - 仅将 %1 扩充到一个文件名

         %~x1        - 仅将 %1 扩充到一个文件扩展名

         %~s1        - 扩充的路径指含有短名

         %~a1        - 将 %1 扩充到文件属性

         %~t1        - 将 %1 扩充到文件的日期/时间

         %~z1        - 将 %1 扩充到文件的大小

         %~$PATH : 1 - 查找列在 PATH 环境变量的目录,并将 %1扩充到找到的第一个完全合格的名称。如果环境变量名未被定义,或者没有找到文件,此组合键会扩充到空字符串可以组合修定符来取得多重结果:

        %~dp1       - 只将 %1 扩展到驱动器号和路径

        %~nx1       - 只将 %1 扩展到文件名和扩展名

        %~dp$PATH:1 - 在列在 PATH 环境变量中的目录里查找 %1,

                       并扩展到找到的第一个文件的驱动器号和路径。

        %~ftza1     - 将 %1 扩展到类似 DIR 的输出行。

    在上面的例子中,%1 和 PATH 可以被其他有效数值替换。

    %~ 语法被一个有效参数号码终止。%~ 修定符不能跟 %*使用。

★★★★★实例★★★★★:

从另一批处理程序运行CHECKNEW.BAT,在父批处理程序中可包含命令:

call checknew

假设父批处理程序接收两个可替换参数,并希望将它们传给CHECKNEW.BAT。可在父批理程序中使用命令:

call checknew %1 %2


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


上一篇:
下一篇: