I have a sh script which calls ffmpeg on several files. When I try to run this script in the background, redirecting output to a file, the job starts but then immediately suspends:
% bin/mp3convert.sh path/a/b &> ~/tmp/log.txt &
[1] 93352
%
[1] + suspended (tty output) bin/mp3convert.sh path/a/b &>
If I try making the script continue in the background, it immediately suspends again:
% jobs
[1] + suspended (tty output) bin/mp3convert.sh path/a/b &>
% bg %1
[1] + continued bin/mp3convert.sh path/a/b &>
% jobs
[1] + suspended (tty output) bin/mp3convert.sh path/a/b &>
%
I can make the script continue, by making it the foreground, but then my terminal is occupied until the script finishes. That means I don't get the benefit of running the script in the background.
%
[1] + suspended (tty output) bin/mp3convert.sh path/a/b &>
% fg %1
[1] + continued bin/mp3convert.sh path/a/b &>
% # much time passes with no activity on terminal, then script finishes
%
How can I make the script run cleanly in the background?
A simplified version of my script is:
#!/bin/sh
# mp3convert.sh
for f in "$1"/*.flac; do
ffmpeg -i "$f" -c:v copy path/to/dest/"$(basename -s .flac "$f")".mp3
done
I am running on Mac OS X 10.11.6, with ffmpeg version 3.4 supplied by MacPorts.
An apparently related question is why do I get “Suspended (tty output)” in one terminal but not in others?. The answer there is to set the terminal state with stty -tostop. That didn't help me; I already had that state set.