HOWTO · Batch
배치 스크립트에서 여러 명령을 동시에 실행
이 자습서에서는 배치 스크립트에서 여러 명령을 동시에 실행하는 방법에 대해 설명합니다.
이 페이지의 내용
때로는 시스템에서 한 번에 여러 작업을 수행해야 합니다. 이 프로세스를 멀티태스킹이라고 합니다. Batch 스크립팅에서는 한 번에 여러 명령을 실행할 수 있습니다.
이 기사에서는 여러 명령을 동시에 실행할 수 있는 방법을 보여주고 주제를 더 쉽게 만들기 위한 몇 가지 예와 설명도 볼 것입니다.
배치 스크립트에서 여러 명령을 동시에 실행
시작하기 전에 동시에 실행하려는 명령 세트는 독립적이어야 합니다. 즉, 하나의 명령이 다른 명령에 종속되지 않습니다.
이 기사에서는 동시에 실행하는 두 가지 다른 방법에 대해 설명합니다. 한 번에 아래 명령을 실행하고 싶다고 가정합니다.
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%19
IPv4 Address. . . . . . . . . . . : 192.168.0.159
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . : 192.168.0.1
배치 스크립트를 사용하여 여러 명령을 동시에 실행하는 방법에 대해 논의했습니다. 필요에 따라 이들 중 하나를 사용할 수 있습니다.
참고: 이 기사에서 공유한 코드는 Batch로 작성되었으며 Windows CMD 전용입니다.