How to Run Multiple Commands Simultaneously in Batch Script
Sometimes, we must perform several tasks in our system at a time. This process is known as multitasking. In Batch scripting, we can run multiple commands at a time.
This article will show how we can run multiple commands simultaneously, and also we will see some examples and explanations to make the topic easier.
Run Multiple Commands Simultaneously in Batch Script
Before we start, please note that the set of commands you wish to run simultaneously should be independent. That means one command will not depend on another command.
In this article, we will discuss two different methods to run simultaneously. Suppose we want to run the below commands at a time,
ping www.google.com
ipconfig /displaydns
Net statistics Workstation
These commands are mainly used to delete cache
Create the .bat
File Containing the Commands
In this section, we are going to do the following steps:
-
First, we must open Notepad and write the commands shared above.
-
We need the file with the
.bat
extension. -
Now, you need to clear the DNS cache. You only need to double-click on the file.
Use Special Characters
Here, we will use a special character for this purpose. You can also follow this method.
We are going to combine all that four steps by using the &
operator like below:
ping www.google.com & ipconfig /displaydns & Net statistics Workstation
Here, if you want to execute one command after another successfully executed, you can use the &&
instead of the &
.
For both of the methods, you will get an output like the one below:
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
We’ve discussed methods to run multiple commands simultaneously using the Batch Script. You can use any one of them based on your needs.
Note: The code we shared in this article is written in Batch and only for the Windows CMD.
Aminul Is an Expert Technical Writer and Full-Stack Developer. He has hands-on working experience on numerous Developer Platforms and SAAS startups. He is highly skilled in numerous Programming languages and Frameworks. He can write professional technical articles like Reviews, Programming, Documentation, SOP, User manual, Whitepaper, etc.
LinkedIn