4
我有一個批量轉換腳本,可以將各種尺寸的.mkvs轉換爲ipod/iphone尺寸的.mp4s,適合的裁剪/縮放。確定原始尺寸,所需的裁剪,輸出文件都工作正常。但是,成功完成第一次轉換後,HandbrakeCLI會導致父腳本退出。爲什麼會這樣?我該如何阻止它?防止子進程(HandbrakeCLI)導致父腳本退出
的代碼,因爲它目前爲:
#!/bin/bash
find . -name "*.mkv" | while read FILE
do
# What would the output file be?
DST=../Touch/$(dirname "$FILE")
MKV=$(basename "$FILE")
MP4=${MKV%%.mkv}.mp4
# If it already exists, don't overwrite it
if [ -e "$DST/$MP4" ]
then
echo "NOT overwriting $DST/$MP4"
else
# Stuff to determine dimensions/cropping removed for brevity
HandbrakeCLI --preset "iPhone & iPod Touch" --vb 900 --crop $crop -i "$FILE" -o "$DST/$MP4" > /dev/null 2>&1
if [ $? != 0 ]
then
echo "$FILE had problems" >> errors.log
fi
fi
done
我已經與另外一個陷阱嘗試過,但並沒有改變行爲(雖然最後沒有陷阱火)
trap "echo Handbrake SIGINT-d" SIGINT
trap "echo Handbrake SIGTERM-d" SIGTERM
trap "echo Handbrake EXIT-d" EXIT
trap "echo Handbrake 0-d" 0
編輯補充:
事實上,'0'陷阱引發了我調查爲什麼這可能是。執行爲bash -x $script
表明find | while read
循環過早結束。
我重新考慮了編碼並將其編碼爲單獨的腳本。查找循環現在是:
find . -name "*.mkv" | while read FILE
do
handbrake-touch "$FILE"
if [ $? != 0 ]
then
echo "$FILE had problems" >> errors.log
fi
done
行爲保持不變 - 一種編碼後跟while循環結束。如果我只是把'echo $ FILE'放在'手剎'的位置,那麼所有的文件都會被列出來。當前目錄不會改變(我想知道什麼可能會破壞find | while
)。
在shebang行的末尾添加'-x'以打開跟蹤並查看出口的確切位置。 – 2010-04-25 13:21:38