一个bat脚本示例

涉及到的主要问题:

for循环内无法set的问题。通过setlocal ENABLEDELAYEDEXPANSION

bat脚本变量作用域的问题 通过setlocal endlocal

变量比较的问题 两边都要有引号

 set qp=22) 注意又括号没有空格,否则set的qp也带有空格了

转义用^


@echo off 

setlocal ENABLEDELAYEDEXPANSION
set count=0
set cfgPath=per-sequence\
for /f "tokens=1-3 delims=-" %%a in (full.template)do (
    set /a count+=1
    for /f "tokens=3" %%f in ('find "FrameRate" "%cfgPath%%%a.cfg"') do (
        ::echo %%f
        if  "%%f" == "20"  ( set intraperiod=16 ) 
        if  "%%f" == "30"  ( set intraperiod=32 )
        if  "%%f" == "50"  ( set intraperiod=48 )
        if  "%%f" == "60"  ( set intraperiod=64 )
        if  "%%f" == "100" ( set intraperiod=96 )
        
        set /a tmp=!count!%%4
        ::set tmp=1
        if  "!tmp!" == "1"  ( set qp=22) 
        if  "!tmp!" == "2"  ( set qp=27)
        if  "!tmp!" == "3"  ( set qp=32)
        if  "!tmp!" == "0"  ( set qp=37)


        if  "%%c" == "randomaccess" ( 
            echo bin\EncoderApp.exe -c encoder_%%c_vtm.cfg -c %cfgPath%%%a.cfg --RateControl=1 --TargetBitrate=%%b -b enc_%%a_%%c_!qp!.bin -o "" -ip !intraperiod! ^>^> enc_%%a_%%c_!qp!.log ^&^& bin\DecoderApp.exe -b enc_%%a_%%c_!qp!.bin -o "" ^>^> dec_%%a_%%c_!qp!.log >>output.txt
        ) else (
            echo bin\EncoderApp.exe -c encoder_%%c_vtm.cfg -c %cfgPath%%%a.cfg --RateControl=1 --TargetBitrate=%%b -b enc_%%a_%%c_!qp!.bin -o "" ^>^> enc_%%a_%%c_!qp!.log ^&^& bin\DecoderApp.exe -b enc_%%a_%%c_!qp!.bin -o "" ^>^> dec_%%a_%%c_!qp!.log >>output.txt
        )
    )
)
endlocal

你可能感兴趣的:(杂)