ffmpeg - Detecting program errors in bash scripts? -
I'm trying to write my first semi-advanced Bash script which, as a file name, is a AV < / Code> Video, convert it to
ffmpeg
and change to a mp4
(preserve the original name) and then place it on MP4Box
.
There's a lot more that I'm doing ...
#! / Usr / bin / bash ffmpeg -i $ 0 -acodec libfaac -ab 128k -ac 2 -vcodec libx264- full punch -crf 22-threads 0 ($ 0) .mp4 MP4Box -inter500 ($ 0) .mp4
- Is there some kind of attempt / hold to make sure I can first program allocation that MP4Box has got practical input?
- Should I also be disturbed with catching the error, should I trust programs for it?
A quick way to execute a program depends on the success of each other < Code> & amp; Amp; & Amp; Amp; (The commands given below are all proxy-codes)
First- cmd & amp; Amp; Second CMD
In this case the second CMD will be executed only if the first-CMD return is correct.
Similarly, you can check the failure and take appropriate action. ||
Bad - CMD || Echo "unsuccessful"
You can add them in different ways:
Good- CMD & amp; Amp; Echo "successful" || Echo "unsuccessful" bad-CMD || {RECOVERY-CMD || Repeat "Recovery failed and echo" Recover "}"
Definitely, it is often apparent to use the variable $?
Others have noted. / P>
You often want to redirect the error message to / dev / null
or capture them in a variable.
bad-cmd 2> gt; / dev / null # bit bucket var = $ (good-CMD) # capture stdout var = $ (bad-CMD2> and 1) #default Error message for # stdout and stderr var = $ (bad-cmd 2> & amp;; 1 & gt; / dev / null) # capture only stderr
In order to obtain additional information for conditional action, you can process the error text.
See:
Comments
Post a Comment