반복문
FOR /L %%a in (1, 1, 5) do TAppEncoder.exe -c config.cfg |
/L in (1,1,5) : 1부터 5까지 1씩 증가시킴, 즉 5번 수행. 이 때 변수인 %%a는 1 부터 5까지.
C코드로 생각하면,
for(a=1; a<5; a++) 로 치환 가능!
따라서 저 위의 batch 코드는. TAppEncoder.exe라는 프로그램을 5번 실행시키라는 의미.
응용 1 :
FOR /L %%a in (1,1,5) do TAppEncoder.exe -c config_%%a.cfg
커맨드 창의 실행 결과는
TAppEncoder.exe -c config_1.cfg
TAppEncoder.exe -c config_2.cfg
TAppEncoder.exe -c config_3.cfg
TAppEncoder.exe -c config_4.cfg
TAppEncoder.exe -c config_5.cfg
즉, %%a자리에 1부터 5까지 차례로 들어감!
응용 2:
FOR /L %%a in (1, 1, 5) do FOR /L %%b in (2, 2, 10) do TAppEncoder.exe -c config_seq%%a_%%b.cfg
커맨드 창의 실행 결과는
TAppEncoder.exe -c config_seq1_2.cfg
TAppEncoder.exe -c config_seq1_4.cfg
TAppEncoder.exe -c config_seq1_6.cfg
TAppEncoder.exe -c config_seq1_8.cfg
TAppEncoder.exe -c config_seq1_10.cfg
...
TAppEncoder.exe -c config_seq5_6.cfg
TAppEncoder.exe -c config_seq5_8.cfg
TAppEncoder.exe -c config_seq5_10.cfg
즉, 이중 for문 가능!
응용 3 :
FOR %%a in (mobile, foreman, newspaper) do TAppEncoder.exe -i %%a.yuv
커맨드 창 실행 결과
TAppEncoder.exe -i mobile.yuv
TAppEncoder.exe -i foreman.yuv
TAppEncoder.exe -i newspaper.yuv
변수는 숫자가 아니어도 된다는거!!
실행 화면 감춤
@echo off |
이 명령어가 입력된 다음 라인부터는 내용이 커맨드 창에 출력되지 않음!