簡體   English   中英

Windows批處理腳本具有多個命令

[英]Windows batch script with multiple commands

好的,所以我有一個Windows 10 .bat腳本,可以使用HandbrakeCLI通過多個命令將所有類型的視頻轉換到一個文件夾中,然后輸出到另一個文件夾中。

除此之外,我想使用CPU使用限制器(如BES)來控制HandbrakeCLI的CPU使用率。

轉換完每個文件后,我想向自己發送一個Pushbullet通知,說明轉換已完成。

下面的代碼幫助我實現了這一點,但是,我需要運行.bat文件兩次才能啟動,並且在一次迭代后停止。

最初在使用多個命令時遇到問題,因此也進行了搜索,並在命令之間使用了“&”,這並不令人高興。

我已經擁有執行所有這些操作的Powershell腳本,因此請不要建議Powershell,我不想使用它,因為Powershell腳本需要我不想再賦予的提升特權。

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

要么

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

//去做

刪除已轉換的文件

更新:使用下面的代碼使其正常工作,但是現在想從每個循環的“ ToConvert”文件夾中刪除轉換后的文件

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

要從ToConvert刪除原始文件,只需在循環末尾添加一個del "%%i" 實際上, %%i擁有文件的絕對路徑。

下面的代碼有效;)

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\*.*"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM