배치 스크립트에서 여러 파일 실행

MD Aminul Islam 2023년3월20일
배치 스크립트에서 여러 파일 실행

큰 스크립트에는 코드 유지 관리가 쉽기 때문에 여러 파일이 포함됩니다. 더 큰 스크립트로 작업할 때 코딩 오류나 문제를 더 쉽게 감지할 수 있도록 스크립트를 모듈로 분할해야 할 수 있습니다.

그러나 Batch에는 개체 지향 기능이 없습니다. 다양한 모듈에 대해 서로 다른 파일을 만들고 코어 파일의 필요와 요구 사항에 따라 모든 파일을 실행할 수 있습니다.

이 기사에서는 단일 Batch 스크립트에서 여러 파일을 실행하는 방법을 보여줍니다. 또한 주제를 쉽게 이해할 수 있도록 몇 가지 예와 설명을 제공합니다.

배치 스크립트에서 여러 파일 실행

이를 위해 CALL이라는 내장 명령을 사용합니다. 현재 파일에서 다른 스크립트 파일을 호출하기 위한 일반 구문은 다음과 같습니다.

CALL YourScript.bat

아래에서 이 주제의 큰 예를 공유했습니다. 아래에 공유된 세 개의 코드를 만들었다고 가정합니다.

file1.bat 내부에는 다음 코드가 있습니다.

ECHO This is from the first file

그리고 file2.bat 내부에는 다음 코드가 있습니다.

ECHO This is from the second file

file3.bat 내부에는 다음 코드가 있습니다.

ECHO This is from the third file

이제 이러한 파일을 호출하는 코어 파일 내부에 다음 코드가 있습니다.

@echo off
ECHO This is the core file that calls all three files...
CALL "file1.bat"
CALL "file2.bat"
CALL "file3.bat"

이제 파일을 실행하면 다음과 같은 결과가 표시됩니다.

This is the core file that calls all three files...
This is from the first file
This is from the second file
This is from the third file

이러한 파일의 디렉토리 외부에서 .bat 파일을 실행하는 경우 기본 파일의 코드를 일부 편집해야 합니다. 코드는 다음과 같습니다.

@echo off
ECHO This is the core file that calls all three files...
CALL "G:\BATCH\file1.bat"
CALL "G:\BATCH\file2.bat"
CALL "G:\BATCH\file3.bat"

파일의 전체 디렉토리만 제공하면 됩니다.

여기에서 논의한 명령은 Windows 명령 프롬프트 또는 CMD 환경에만 해당된다는 점을 기억하십시오.

MD Aminul Islam avatar MD Aminul Islam avatar

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

관련 문장 - Batch File