JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Running multiple commands simultaneously in a batch script

Author:JIYIK Last Updated:2025/03/21 Views:

Sometimes, we have to perform multiple tasks in the system at a time. This process is called multitasking. In batch scripts, we can run multiple commands at a time.

This article will show how to run multiple commands simultaneously, and we will also see some examples and explanations to make the topic easier.


Running multiple commands simultaneously in a batch script

Before you begin, please note that the set of commands you wish to run simultaneously should be independent. This means that one command should not depend on another.

In this article, we will discuss two different ways to run things at the same time. Suppose we want to run the following commands at once,

ping www.google.com
ipconfig /displaydns
Net statistics Workstation

These commands are mainly used to delete cache

Create a .bat file containing the commands

In this section, we will perform the following steps:

  • First, we have to open Notepad and write the command shared above.
  • We need a file with a .bat extension.
  • Now you need to clear your DNS cache. You can do this by simply double-clicking on the file.

Using special characters

Here, we will use a special character to achieve this. You can also follow this method.

We will &combine all four steps using the operator as follows:

ping www.google.com & ipconfig /displaydns & Net statistics Workstation

Here, if you want to execute one command after another is successfully executed, you can use &&instead of &.

For both methods, you will get output similar to the following:

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 have discussed the methods of running multiple commands simultaneously using batch scripts. You can use any of them according to your requirement.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Reading file into variable in batch script

Publish Date:2025/03/22 Views:121 Category:OPERATING SYSTEM

Sometimes, we need to put the entire contents of a file into a variable for various purposes, such as finding specific data from a file, replacing a specific part of a file, etc. In Batch, it is very easy to put the entire file contents in

Declaring variables in batch script

Publish Date:2025/03/22 Views:66 Category:OPERATING SYSTEM

This article will demonstrate how to declare and define variables in a batch script. Declaring variables in batch script In Batch, you do not need to use any additional keywords to declare integer, float, double, or string type variables. T

Replace text in a file in batch script

Publish Date:2025/03/21 Views:105 Category:OPERATING SYSTEM

In this article, we will look at some ways to replace text in a file. We will look at two different ways. Our first approach consists only of a batch script to perform the task, while the second approach provides a solution through Windows

Running batch scripts in C#

Publish Date:2025/03/21 Views:139 Category:OPERATING SYSTEM

In this article, we will see how to write a C# program that can run a batch file from a directory. Running batch scripts in C# In C#, when we want to execute a batch file, it acts as a process. You can follow the sample code below to run a

Extract or unzip files in batch script

Publish Date:2025/03/21 Views:122 Category:OPERATING SYSTEM

In this article, we will see how to create a batch script to extract files from a zip file. Create a batch script to unzip the files We can extract or decompress files using batch scripts which need to contain the destination directory wher

Transferring files to Raspberry Pi using batch script

Publish Date:2025/03/21 Views:58 Category:OPERATING SYSTEM

This article will show a batch command that transfers a file from Windows to the Raspberry Pi environment and executes the file. PuTTY is a third-party free tool that implements Telnet and SSH for Windows and Unix platforms for free. It als

Renaming part of a file name in a batch script

Publish Date:2025/03/21 Views:124 Category:OPERATING SYSTEM

Sometimes we need to rename a series of files in a specific order. Most project files contain this sequence, and we can easily do this in a batch script using a simple one-line command. This short article will show us how to change a specif

Run batch scripts using Task Scheduler

Publish Date:2025/03/21 Views:153 Category:OPERATING SYSTEM

This article will show you how to use Task Scheduler to run a batch file. Run batch scripts using Task Scheduler With Task Scheduler, you can automate tasks to run automatically at specific times. It only takes a few steps and you don't nee

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial