HOWTO · Batch
バッチ スクリプトで複数のコマンドを同時に実行する
このチュートリアルでは、バッチ スクリプトで複数のコマンドを同時に実行する方法について説明します。
このページの内容
システムで一度に複数のタスクを実行する必要がある場合があります。 このプロセスはマルチタスクと呼ばれます。 バッチ スクリプトでは、一度に複数のコマンドを実行できます。
この記事では、複数のコマンドを同時に実行する方法を示します。また、トピックを簡単にするために、いくつかの例と説明も示します。
バッチ スクリプトで複数のコマンドを同時に実行する
開始する前に、同時に実行するコマンドのセットは独立している必要があることに注意してください。 つまり、あるコマンドは別のコマンドに依存しません。
この記事では、同時に実行する 2つの異なる方法について説明します。 以下のコマンドを一度に実行したいとします。
ping www.google.com
ipconfig /displaydns
Net statistics Workstation
これらのコマンドは、主にキャッシュを削除するために使用されます
コマンドを含む .bat ファイルを作成する
このセクションでは、次の手順を実行します。
-
まず、メモ帳を開いて、上記で共有したコマンドを書き込む必要があります。
-
.bat拡張子を持つファイルが必要です。 -
ここで、DNS キャッシュをクリアする必要があります。 ファイルをダブルクリックするだけです。
特殊文字を使用する
ここでは、この目的のために特殊文字を使用します。 この方法に従うこともできます。
以下のように & 演算子を使用して、これら 4つのステップをすべて結合します。
ping www.google.com & ipconfig /displaydns & Net statistics Workstation
ここで、別のコマンドが正常に実行された後に 1つのコマンドを実行したい場合は、& の代わりに && を使用できます。
どちらの方法でも、次のような出力が得られます。
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%19
IPv4 Address. . . . . . . . . . . : 192.168.0.159
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
バッチ スクリプトを使用して複数のコマンドを同時に実行する方法について説明しました。 必要に応じて、それらのいずれかを使用できます。
注: この記事で共有したコードは Batch で記述されており、Windows CMD 専用です。