如何调用一个又一个批处理文件
我有一个正在测试的批处理文件,我想做的就是以下
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
检查第一批中的某个位置是否有
exit
。有些人习惯性地使用它来跳出批处理文件,这不是退出批处理的正确方法(exit /b
或goto :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
orgoto :eof
is).Another option is that you might call another batch in the first one without
call
.正如您所说,如果您的
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 merelyping 127.0.0.1
, as you say.I would append
.exe
afterping
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.
假设您有 3 个批处理文件。
调用 ping1.bat
调用 ping2.bat
如果您将所有三个批处理文件放在一个文件夹中(假设在 C:\NewFolder 下)
那么如果你双击 ping3.bat,你肯定不会得到任何错误。
注意:如果您不想等待第一个命令完成,请使用 start 关键字,它只是启动进程并继续处理批处理文件中的下一行,而调用
将按顺序执行(仅在当前进程完成后才进入下一行,开始允许并行)
要并行执行此操作,请在 ping3.bat 中使用以下两行代码:
start ping1.bat
启动 ping2.bat
Assume you have 3 batch files.
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
不要将您从批处理中调用的文件与您尝试调用的命令同名...重命名为 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
不太确定您想在这里做什么,但我假设您想这样做:
在这种情况下,从实际的批处理文件中,您应该启动 ping.bat 和 ping2.bat像这样:
那么在ping.bat和ping2.bat中,最后一行应该是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:
In that case, from your actual batch file, you should start ping.bat and ping2.bat like this:
Then in both ping.bat and ping2.bat the last line should be exit. Their code should look like this:
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.
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