在批处理脚本中同时运行多个命令
有时,我们必须一次在系统中执行多项任务。 这个过程称为多任务处理。 在批处理脚本中,我们可以一次运行多个命令。
本文将展示如何同时运行多个命令,并且我们还将看到一些示例和解释以使主题变得更容易。
在批处理脚本中同时运行多个命令
在开始之前,请注意您希望同时运行的命令集应该是独立的。 这意味着一个命令不会依赖于另一命令。
在本文中,我们将讨论同时运行的两种不同方法。 假设我们想一次运行以下命令,
ping www.google.com
ipconfig /displaydns
net statistics workstation
这些命令主要用于删除缓存
创建包含命令的 .bat 文件
在本节中,我们将执行以下步骤:
- 首先,我们必须打开记事本并写入上面共享的命令。
- 我们需要扩展名为 .bat 的文件。
- 现在,您需要清除 dns 缓存。 您只需双击该文件即可。
使用特殊字符
在这里,我们将使用一个特殊字符来实现此目的。 您也可以遵循此方法。
我们将使用 &
运算符组合所有四个步骤,如下所示:
ping www.google.com & ipconfig /displaydns & net statistics workstation
在这里,如果您想在成功执行一条命令后执行另一条命令,则可以使用 &&
而不是 &
。
对于这两种方法,您都会得到如下所示的输出:
pinging www.google.com [142.250.195.100] with 32 bytes of data:
reply from 142.250.195.100: bytes=32 time=59ms ttl=114
reply from 142.250.195.100: bytes=32 time=60ms ttl=114
reply from 142.250.195.100: bytes=32 time=60ms ttl=114
reply from 142.250.195.100: bytes=32 time=58ms ttl=114
ping statistics for 142.250.195.100:
packets: sent = 4, received = 4, lost = 0 (0% loss),
approximate round trip times in milli-seconds:
minimum = 58ms, maximum = 60ms, average = 59ms
windows ip configuration
ec2-52-23-111-175.compute-1.amazonaws.com
----------------------------------------
record name . . . . . : ec2-52-23-111-175.compute-1.amazonaws.com
record type . . . . . : 1
time to live . . . . : 8903
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 52.23.111.175
www.google.com
----------------------------------------
record name . . . . . : www.google.com
record type . . . . . : 1
time to live . . . . : 174
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 142.250.195.100
cdn.discordapp.com
----------------------------------------
record name . . . . . : cdn.discordapp.com
record type . . . . . : 1
time to live . . . . : 137
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 162.159.129.233
record name . . . . . : cdn.discordapp.com
record type . . . . . : 1
time to live . . . . : 137
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 162.159.133.233
record name . . . . . : cdn.discordapp.com
record type . . . . . : 1
time to live . . . . : 137
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 162.159.134.233
record name . . . . . : cdn.discordapp.com
record type . . . . . : 1
time to live . . . . : 137
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 162.159.135.233
record name . . . . . : cdn.discordapp.com
record type . . . . . : 1
time to live . . . . : 137
data length . . . . . : 4
section . . . . . . . : answer
a (host) record . . . : 162.159.130.233
workstation statistics for \\desktop-nrta4bb
statistics since 9/25/2022 1:33:19 pm
bytes received 667340
server message blocks (smbs) received 84
bytes transmitted 611958
server message blocks (smbs) transmitted 0
read operations 0
write operations 0
raw reads denied 0
raw writes denied 0
network errors 0
connections made 0
reconnections made 0
server disconnects 0
sessions started 0
hung sessions 0
failed sessions 0
failed operations 0
use count 84
failed use count 0
the command completed successfully.
windows ip configuration
no operation can be performed on ethernet while it has its media disconnected.
no operation can be performed on local area connection* 1 while it has its media disconnected.
no operation can be performed on local area connection* 2 while it has its media disconnected.
ethernet adapter ethernet:
media state . . . . . . . . . . . : media disconnected
connection-specific dns suffix . :
wireless lan adapter local area connection* 1:
media state . . . . . . . . . . . : media disconnected
connection-specific dns suffix . :
wireless lan adapter local area connection* 2:
media state . . . . . . . . . . . : media disconnected
connection-specific dns suffix . :
wireless lan adapter wi-fi:
connection-specific dns suffix . :
link-local ipv6 address . . . . . : fe80::6cf3:f1dd:2862:c40c
ipv4 address. . . . . . . . . . . : 192.168.0.159
subnet mask . . . . . . . . . . . : 255.255.255.0
default gateway . . . . . . . . . : 192.168.0.1
我们讨论了使用批处理脚本同时运行多个命令的方法。 您可以根据需要使用其中任何一种。
转载请发邮件至 1244347461@qq.com 进行申请,经作者同意之后,转载请以链接形式注明出处
本文地址:
相关文章
发布时间:2024/03/15 浏览次数:75 分类:编程语言
-
本教程将展示我们如何在批处理脚本中包含或添加注释。
发布时间:2024/03/15 浏览次数:186 分类:编程语言
-
本教程将展示在批处理脚本中使用 pause 关键字。
发布时间:2024/03/15 浏览次数:205 分类:编程语言
-
本教程将教授批处理脚本中的颜色。
发布时间:2024/03/15 浏览次数:118 分类:编程语言
-
本教程将讨论批处理脚本中 if else 条件的结构。
发布时间:2024/03/15 浏览次数:148 分类:编程语言
-
本教程将了解我们如何使用批处理脚本发送邮件。
发布时间:2024/03/15 浏览次数:192 分类:编程语言
-
本教程将讨论如何在批处理脚本中声明数组。
发布时间:2024/03/15 浏览次数:193 分类:编程语言
-
本文讨论了如何通过代码示例在批处理脚本中获取或查找时间和日期。
发布时间:2024/03/15 浏览次数:147 分类:编程语言
-
本教程将讨论如何在批处理脚本中创建函数。