Ejecute varios comandos simultáneamente en Batch Script
 
En ocasiones, debemos realizar varias tareas en nuestro sistema a la vez. Este proceso se conoce como multitarea. En las secuencias de Batch comandos, podemos ejecutar varios comandos a la vez.
Este artículo mostrará cómo podemos ejecutar múltiples comandos simultáneamente, y también veremos algunos ejemplos y explicaciones para facilitar el tema.
Ejecute varios comandos simultáneamente en Batch Script
Antes de comenzar, tenga en cuenta que el conjunto de comandos que desea ejecutar simultáneamente debe ser independiente. Eso significa que un comando no dependerá de otro comando.
En este artículo, discutiremos dos métodos diferentes para ejecutar simultáneamente. Supongamos que queremos ejecutar los siguientes comandos a la vez,
ping www.google.com
ipconfig /displaydns
Net statistics Workstation
Estos comandos se utilizan principalmente para eliminar el caché.
Cree el archivo .bat que contiene los comandos
En esta sección vamos a realizar los siguientes pasos:
- 
Primero, debemos abrir el Bloc de notas y escribir los comandos compartidos anteriormente.
- 
Necesitamos el archivo con extensión.bat.
- 
Ahora, debe borrar el caché de DNS. Solo necesita hacer doble clic en el archivo.
Usar caracteres especiales
Aquí, usaremos un carácter especial para este propósito. También puedes seguir este método.
Vamos a combinar todos esos cuatro pasos usando el operador & como se muestra a continuación:
ping www.google.com & ipconfig /displaydns & Net statistics Workstation
Aquí, si desea ejecutar un comando tras otro ejecutado con éxito, puede usar && en lugar de &.
Para ambos métodos, obtendrá un resultado como el siguiente:
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
Hemos discutido métodos para ejecutar múltiples comandos simultáneamente usando Batch Script. Puede utilizar cualquiera de ellos en función de sus necesidades.
Nota: El código que compartimos en este artículo está escrito en Batch y solo para 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