如何调用一个又一个批处理文件

发布于 2024-10-28 02:13:20 字数 324 浏览 3 评论 0原文

我有一个正在测试的批处理文件,我想做的就是以下

CALL ping.bat

然后在该批处理文件运行后我想运行另一个文件:

CALL ping2.bat

现在我在一个批处理文件中将这两行并排放置在第一个批处理文件中会成功发射,但第二个不会。有什么建议吗?

CALL ping.bat
CALL ping2.bat

Ping .bat 只是:

ping 127.0.0.1    

I have a batch file that i am testing, all i want to do is the following

CALL ping.bat

Then after that batch file has run i want to run another file:

CALL ping2.bat

Right now i have these two lines beside each other in a batch file the first batch file will fire successfully but the second one does not . Any suggestions?

CALL ping.bat
CALL ping2.bat

Ping .bat is just:

ping 127.0.0.1    

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

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

发布评论

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

评论(6

素手挽清风 2024-11-04 02:13:20

检查第一批中的某个位置是否有 exit。有些人习惯性地使用它来跳出批处理文件,这不是退出批处理的正确方法(exit /bgoto :eof 是)。

另一种选择是,您可以在第一个批处理中调用另一个批处理,而无需调用

Check that you don't have exit somewhere in the first batch. Some people habitually use that to jump out of a batch file which is not the proper way to exit a batch (exit /b or goto :eof is).

Another option is that you might call another batch in the first one without call.

白昼 2024-11-04 02:13:20

正如您所说,如果您的 ping.bat 的内容只是 ping 127.0.0.1,那么您的 ping.bat 可能只是在调用自身。

我会在 ping 之后附加 .exe 以确保一切顺利。

正如 jeb 所建议的那样,为批处理文件选择不同的名称是更好的解决方案。

There's a chance your ping.bat is simply calling itself, if its contents is merely ping 127.0.0.1, as you say.

I would append .exe after ping to make things sure.

As jeb has by all means justly suggested, choosing a different name for your batch file is an even better solution.

忘年祭陌 2024-11-04 02:13:20

假设您有 3 个批处理文件。

  1. ping1.bat 的内容为 ping 127.0.0.1
  2. ping2.bat 的内容为 ping 127.0.0.1
  3. ping3.bat 的内容有以下两行
    调用 ping1.bat
    调用 ping2.bat

如果您将所有三个批处理文件放在一个文件夹中(假设在 C:\NewFolder 下)
那么如果你双击 ping3.bat,你肯定不会得到任何错误。

注意:如果您不想等待第一个命令完成,请使用 start 关键字,它只是启动进程并继续处理批处理文件中的下一行,而调用
将按顺序执行(仅在当前进程完成后才进入下一行,开始允许并行)
要并行执行此操作,请在 ping3.bat 中使用以下两行代码:

start ping1.bat
启动 ping2.bat

Assume you have 3 batch files.

  1. ping1.bat which has the content ping 127.0.0.1
  2. ping2.bat which has the content ping 127.0.0.1
  3. ping3.bat which has the below two lines
    call ping1.bat
    call ping2.bat

If you have all the three batch files in a single folder,(lets say under C:\NewFolder)
then if you double click ping3.bat, you won't get any error for sure.

Note: If you don't want to wait for the first command to complete, then use start keyword which just initiate the process and proceed with the next line in the batch file, whereas call
will do it sequentially(comes to next line only after the current process completes , start allows parallelism)
To do it parallel use the below two lines of code in the ping3.bat:

start ping1.bat
start ping2.bat

苍暮颜 2024-11-04 02:13:20

不要将您从批处理中调用的文件与您尝试调用的命令同名...重命名为 gnip.bat 并且工作正常

don't call the file you are calling from the batch the same name as the command you are trying to invoke...renamed to gnip.bat and works fine

深海夜未眠 2024-11-04 02:13:20

不太确定您想在这里做什么,但我假设您想这样做:

  1. 从 FIRST.bat运行 FIRST.bat
  2. 您希望调用 SECOND.bat
  3. 当 SECOND.bat 正在执行时,FIRST.bat 应
  4. 在 SECOND 之后 保持暂停状态.bat 完成执行,FIRST.bat 应该恢复并调用 THIRD.bat

在这种情况下,从实际的批处理文件中,您应该启动 ping.batping2.bat像这样:

::some code here
start /wait ping.bat
start /wait ping2.bat
::some code here

那么在ping.batping2.bat中,最后一行应该是exit。他们的代码应该如下所示:

::some code here, might be ping 127.0.0.1
exit

所以现在您的实际批处理文件将启动 ping.bat 并等待它完成(退出)。一旦 ping.bat 关闭,您的实际批处理文件将转到下一行,并将启动 ping2.bat 等。

Not exactly sure what you wanted to do here, but I assume that you wanted to do this:

  1. run FIRST.bat
  2. from FIRST.bat you wish to call SECOND.bat
  3. While SECOND.bat is executing, FIRST.bat should remain paused
  4. After SECOND.bat finishes its execution, FIRST.bat should resume and call THIRD.bat

In that case, from your actual batch file, you should start ping.bat and ping2.bat like this:

::some code here
start /wait ping.bat
start /wait ping2.bat
::some code here

Then in both ping.bat and ping2.bat the last line should be exit. Their code should look like this:

::some code here, might be ping 127.0.0.1
exit

So now your actual batch file will start ping.bat and it will wait for it to finish (exit). Once the ping.bat closes, your actual batch file will go to the next line and it will start ping2.bat etc.

反话 2024-11-04 02:13:20

ping 命令在不同操作系统上的作用有所不同。尝试使用 -n 开关强制 ping 命令在几次回显请求后停止。

平-n 4 127.0.0.1

The ping command acts differently on different operating systems. Try forcing the ping command to stop after a few echo requests with a -n switch.

ping -n 4 127.0.0.1

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