cmd.exe:何时使用调用来运行外部程序

发布于 2024-10-15 00:49:41 字数 143 浏览 0 评论 0原文

似乎包含以下内容的 cmd 脚本

prog1
prog2

call prog1
call prog2

与使用 CALL 命令有何意义

It seems that a cmd script containing:

prog1
prog2

does the same as

call prog1
call prog2

What is the point of using the CALL command ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单气质女生网名 2024-10-22 00:49:41

当您想要执行以下任一操作时,应该使用call

  • 调用另一个命令文件并在完成后返回到此命令文件。;或者
  • 调用当前命令文件中的函数。

包含以下行的命令文件:

number2.cmd

链接number2.cmd 文件,这意味着它将运行该脚本,但不会返回以继续执行当前脚本。

对于第二点,您可以执行以下操作:

call :subroutine
call :subroutine
goto :eof

:subroutine
    echo in here
    goto :eof

您将在 in here 中打印两次。这种在命令脚本中调用函数的能力实际上非常方便。

You should use call when you either want to:

  • call another command file and return to this one when it's done. ; or
  • call a function in the current command file.

A command file with the line:

number2.cmd

will chain to the number2.cmd file, meaning it will run that script but not return to continue execution on the current one.

As to the second point, you can do things like:

call :subroutine
call :subroutine
goto :eof

:subroutine
    echo in here
    goto :eof

and you will get in here printed twice. This ability to call functions within command scripts is actually quite handy.

反差帅 2024-10-22 00:49:41

当您需要调用另一个批处理程序(cmd 脚本)时,您应该使用call。如果 prog1 是可执行文件,则使用“call”将不起作用。 (prog1.exe)

例如,如果您有两个脚本:

cmd1.cmd
cmd2.cmd

并且在 cmd1.cmd 中您有一行:

cmd2.cmd

... 那么您的脚本将在以下情况下立即停止 : cmd2.cmd 执行完毕。相反,你应该使用:

call cmd2.cmd

You should use call when you need to call another batch program (cmd script). Using 'call' will have no effect if prog1 is an executable file. (prog1.exe)

If you, for example, have two scripts:

cmd1.cmd
cmd2.cmd

And within cmd1.cmd you have a line:

cmd2.cmd

... then your script will stop as soon as cmd2.cmd is finished executing. Instead you should use:

call cmd2.cmd
饮湿 2024-10-22 00:49:41

通常,调用用于运行一个批处理文件中的另一个批处理文件。当调用的批处理文件完成时,原始批处理文件的其余部分也完成。

请注意,如果批处理文件不存在,则会给出错误消息。

语法是: CALL [drive:][path]filename [batch-parameters]

在哪里调用它没有限制。您可以在任何批处理文件中使用 CALL 命令来调用另一个批处理文件。

希望这有帮助。

Normally call is used to run another batch file within a batch file. When the batch file that is called is completed, the remainder of the original batch file is completed.

Note if the batch file does not exist it will give an error message.

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

There are no restriction in where to call it. You can use CALL command in any batch file to call another batch file.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文