bash脚本在while循环中停止执行-为什么? [英] bash script stops execution in while loop - why?

查看:126
本文介绍了bash脚本在while循环中停止执行-为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个bash脚本,用于将.mp4视频转换为.mp3音频. 它可以运行,但是只循环一次,尽管/home/myname/mp4dir中有更多的mp4文件.该脚本会将找到的第一个.mp4文件转换为.mp3,除非已经存在一个.mp3文件.这应该循环执行,但是在首次调用ffmpeg之后,脚本将停止. 为什么?

I have this bash script for converting .mp4 video to .mp3 audio. It runs, but does the loop only once, though there are more mp4 files in /home/myname/mp4dir. The script converts the first .mp4 file it finds to .mp3, unless there is already an .mp3 file. This should be done in a loop, but after the first call to ffmpeg the script stops. Why?

#!/bin/bash
find /home/myname/mp4dir -name "*.mp4" | while read f
do
        fOut=`echo $f | sed s/mp4/mp3/`
        echo "convert $f => $fOut"
        if ! test -f $fOut
        then
                ffmpeg -i $f -vn -f mp3 $fOut
        fi
done

推荐答案

从注释中我们可以发现,实际上有您正在循环的输入文件(无论哪种类型),并且ffmpeg至少启动一次.然后,您被卡住了.

From the comments we got that there actually are input files you are looping over (of what kind soever) and that ffmpeg at least starts once. Then, you are stuck.

添加

&> ffmpeg.outerr < /dev/null 

ffmpeg命令并监视文件ffmpeg.outerr,同时执行循环"(即ffmpeg).它会告诉您问题所在.您既可以自己解决此问题,也可以使用标签ffmpeg回到这个特定于ffmpeg的问题的stackoverflow.

to your ffmpeg command and monitor the file ffmpeg.outerr while your "loop", i.e. ffmpeg, executes. It will tell you what the problem is. Either you can solve this problem yourself, or you come back to stackoverflow with this ffmpeg-specific problem using the tag ffmpeg.

这篇关于bash脚本在while循环中停止执行-为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆