Search code examples
windowscmdbatch-processinghandbrake

Windows batch script with multiple commands


Ok, so I have a Windows 10 .bat script to convert all type videos in one folder and output in another using HandbrakeCLI with multiple commands.

In addition to that, I want to use a CPU usage limiter like BES to control the CPU usage of HandbrakeCLI.

After each file is converted, I want to then send a Pushbullet notification to myself stating that the conversion is complete.

The code below helps me achieve that, I however need to run the .bat file twice to make start and after one iteration it stops.

Initially had problems using multiple commands and so did a search and used "&" between commands, no joy.

I already have a Powershell script which does all this, so please don't suggest Powershell, I don't want to use it because the Powershell script requires elevated privileges which I don't want to give anymore.

FOR /R "D:\ToConvert" %%i IN (*.*) DO "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize & "C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -t 1 -c 1 -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize & powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted"" & taskkill /im BES.exe

OR

call "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize
for /r "D:\ToConvert" %%i IN (*) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize
powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted""
)
taskkill /im BES.exe
exit /b

//TODO

Delete the already converted file

Update: Got it to work using the code below however now want to delete the converted file from the "ToConvert" folder for each loop

start "" "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize
for /r "D:\ToConvert" %%i IN (*) do (
"C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize
powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted""
)
taskkill /im BES.exe

Solution

  • The code below worked ;)

    start "" "C:\Program Files (x86)\BES_1.6.2\BES.exe" "C:\Program Files\Handbrake\HandBrakeCLI.exe" 33 --minimize
    for /r "D:\ToConvert" %%i IN (*) do (
    "C:\Program Files\HandBrake\HandBrakeCLI.exe" -i "%%i" -o "D:\Done\%%~ni.mp4" --preset="Normal" --optimize
    powershell -ExecutionPolicy Bypass -command "D:\Scripts\SendPushBullet.ps1 "%%~ni" " Converted""
    )
    taskkill /im BES.exe
    del /f /q "D:\ToConvert\*.*"