简体   繁体   English

特殊字符导致Windows批处理文件关闭

[英]Special characters cause the Windows Batch File to close

So I created a windows batch script to convert videos using the HandbrakeCLI 所以我创建了一个Windows批处理脚本来使用HandbrakeCLI转换视频

Batch script: 批处理脚本:

@echo off
::SET TO CURRENT CODE PAGE:::::::::::::::::::::::::::
FOR /F "tokens=4 delims= " %%G in ('chcp') DO (
chcp %%G >nul
) 
:::::::::::::::::::::::::::::::::::::::::::::::::::::
setlocal EnableExtensions
title AniCoder v2.5 by Nightsanity
color 0a
cd "%~d0%~p0"

::PREVENT MULTIPLE HANDBRAKE PROCESSES::::::::::::::::
set ignore=INFO:
for /f "usebackq" %%A in (`tasklist /nh /fi "imagename eq HandBrakeCLI.exe"`) do if not %%A==%ignore% (
exit
)
::::::::::::::::::::::::::::::::::::::::::::::::::::::

::PREREQUISITES CHECK:::::::::::::::::::::::::::::::::
if not exist "HandBrakeCLI.exe" (
echo HandBrakeCLI is missing!
pause 
exit
)
if exist "Jobs.txt" del "Jobs.txt"
if not exist "ToConvert" mkdir "ToConvert"
if not exist "Converted" mkdir "Converted"
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::CREATE A LIST OF VIDEOS TO CONVERT:::::::::::::::::::
for /F %%i in ('dir /s /b "ToConvert\*.*"') do (
dir/s/b "ToConvert\*" >> "Jobs.txt"
goto MAIN
)
goto NOFILES
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::LOOP THROUGH JOBS LIST AND CONVERT FILES:::::::::::::
:MAIN
for /f "tokens=* delims= " %%a in (Jobs.txt) do (
HandBrakeCLI -i "./ToConvert/%%~nxa" -f mp4 -o "./Converted/%%~na.mp4" -q 22 -e x264 -x cabac=0:ref=2:me=hex:bframes=0:weightp=0:subme=6:8x8dct=0:trellis=0 -E faac --mixdown mono -B 64 -X 480 -l 272 -s 1 --subtitle-burn -a 1
)
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::CLEAN UP FILES:::::::::::::::::::::::::::::::::::::::
if exist "Jobs.txt" del "Jobs.txt"
:Question
cls
echo Encode Done!
echo.
set DELFILES=
set /p DELFILES="Do you want to delete original files (Y/N)?:"
if "%DELFILES%" == "y" goto DELNOW
if "%DELFILES%" == "Y" goto DELNOW
if "%DELFILES%" == "n" goto ENDNOW
if "%DELFILES%" == "N" goto ENDNOW
goto Question
:DELNOW
if exist "ToConvert\*.*" del /Q "ToConvert\*.*"
:ENDNOW
endlocal
exit
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

::WHEN NO FILES ARE INSIDE TOCONVERT FOLDER::::::::::::
:NOFILES
echo No video files found in:
echo ToConvert folder
echo.
pause
:::::::::::::::::::::::::::::::::::::::::::::::::::::::

HandbrakeCLI reference: trac.handbrake.fr/wiki/CLIGuide HandbrakeCLI参考: trac.handbrake.fr/wiki/CLIGuide

I have ran into a problem where if there is a special character in the path for example a German Umlaut it will not interpret it or something as it wont convert and close the window. 我遇到了一个问题,如果路径中有一个特殊字符,例如德国Umlaut,它将无法解释该字符或其他内容,因为它将无法转换并关闭窗口。

How can I workaround this issue? 如何解决此问题?

Running Windows 7 Home Premium Sp1 运行Windows 7 Home Premium Sp1

I'd suggest you change 我建议你改变

for /F %%i in ('dir /s /b "ToConvert\*.*"') do (
 dir/s/b "ToConvert\*" >> "Jobs.txt"

to

for /F "delims=" %%i in ('dir /s /b "ToConvert\*.*"') do (
 echo(%%~dspnxi >> "Jobs.txt"

to output the shortname to jobs.tst . 将短名称输出到jobs.tst

or perhaps 也许

 echo(%%~dspi%%~nxi >> "Jobs.txt"

may be better. 可能更好。

(can't test - no test directories available to me) (无法测试-我没有可用的测试目录)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM