For faster navigation, this Iframe is preloading the Wikiwand page for 배치 파일.

배치 파일

배치 파일
파일 확장자.bat, .cmd, .btm
인터넷 미디어 타입
  • application/bat
  • application/x-bat
  • application/x-msdos-program
  • text/plain
포맷 종류스크립트
다음의 컨테이너스크립트

MS-DOS, OS/2, 윈도우에서 쓰이는 배치 파일(batch file)은 명령 인터프리터에 의해 실행되게끔 고안된 명령어들이 나열되어 있는 텍스트 파일이다. 배치 파일이 실행될 때, COMMAND.COM 또는 cmd.exe와 같은 프로그램이 파일을 읽어 명령어를 줄 단위로 실행한다. 배치 파일은 보통 실행 파일을 자동으로, 연속적으로 실행할 때 유용하며 시스템 관리자가 따분한 일들을 자동화하기 위해 자주 사용한다.

유닉스 계열 운영체제에서 배치 파일은 셸 스크립트와 닮아 있지만, 구문과 명령어가 제한이 되어 있기 때문에 일반 목적의 프로그래밍에 적합하지 않다. 이러한 제한을 해결하려면 DOS 시절의 경우 노턴 유틸리티나 이후에 나온 셸 4DOS와 같은 넓은 용도의 "강화" 명령어를 사용하면 된다.

파일 확장자

[편집]

도스에서는 배치 파일의 확장자로 .BAT를, 윈도우 NTOS/2에서는 .CMD를, 4DOS에서는 BTM을 도입하였다.

  • .bat: 마이크로소프트가 배치 파일에 사용한 최초의 파일 확장자. 이 확장자는 MS-DOS와 모든 버전의 윈도우에서 COMMAND.COM 또는 cmd.exe를 통해 실행된다.
  • .cmd: 윈도우 NT 계열에서 배치 파일에 사용되며 해석을 위해 cmd.exe로 내보낸다. COMMAND.COM은 이 파일 확장자를 식별하지 못한다.
  • .btm: 4DOS와 4NT에 쓰이는 확장자이다 4DOS와 NT에서 실행되는 스크립트들은 특히 더 긴 이름을 사용할 때 속도가 더 빠른데, 실행을 위해 스크립트를 줄 단위로 실행하지 않고 스크립트를 완전히 불러들인 상태에서 진행하기 때문이다.[1]

예제

[편집]

단순한 배치 파일의 예제는 다음과 같다: (rem은 주석 처리를 말함)

 rem 알림:echo off는 [[표준 출력]]에 각 명령을 출력하지 않게 하는 명령어이다.
 @echo off
 rem 알림:echo.는 빈 줄을 하나 출력한다.
 echo.
 echo [[Hello World]], AProgram.exe를 실행하려면 아무 키나 누르십시오!
 pause > nul
 rem 알림: 배치 파일에 대한 첫 [[매개변수]]는 "%1"로 지정하면 된다.
 AProgram.exe %1
 if errorlevel 1 goto error
 echo.
 echo AProgram이 끝났습니다.
 goto end
 :error
 echo.
 echo AProgram에 무언가가 잘못된 것 같습니다.
 :end

명령 프롬프트 위치

[편집]

윈도우 비스타 이후부터는 명령 프롬프트가 사용자 계정 컨트롤(UAC)이 켜져있는 상태에서는 특정위치를 가리키게 되어있으므로, 실행할 파일의 절대경로를 참조하거나, CD /D "%~DP0"나 PUSHD "%~DP0" 명령어를 사용해야하는 일이 발생할 수 있다.[2]

같이 보기

[편집]

각주

[편집]
{{bottomLinkPreText}} {{bottomLinkText}}
배치 파일
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?