Condition to check if a command printed something to stdout

Viewed 291

I am trying to create a loop that will return pass or fail if something is printed to stdout using the command below. The command will print info to the screen if a video has audio and it will print nothing if it doesn't. Currently the loop only prints pass on both the audio and non audio files. Is there a way to set the condition to stdout and determine if something was printed?

ffprobe -i INPUT -show_streams -select_streams a -loglevel error >/dev/null
if [ $? == 0 ]
then    
    echo pass
else
    echo fail
fi
1 Answers

Save the output in a variable instead of redirecting it to /dev/null, then test if the output is empty or not.

out=$(ffprobe -i INPUT -show_streams -select_streams a -loglevel error)
if [ -n "$out" ]
then    
    echo pass
else
    echo fail
fi
Related