0

Given:

An ffprobe command that detects duration of an mp4 video files on a remote host.

Expected:

Output of ffprobe is prefixed with custom string and redirected to a text file.

Problem:

Sometimes due to network error, ffprobe fails with some error message. I would like to capture that error, prefix it with a custom string and send it to a text file.

Example:

This command appends "ABC=55" to out.txt where 55 is the discovered duration:

ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 https://example.com/video.mp4' | awk '{print "ABC="$1}' 2>&1 >> out.txt

However, if that same command encounters a network error, instead of writing "ABC=Error message here", it writes noting to text file and shows that message in console.

Question

How do I tweak this part to capture execution errors, prefix them with "ABC=" and send to out.txt?

| awk '{print "ABC="$1}' 2>&1 >> out.txt

Thank you.

EDIT

This solved the problem:

2>&1 | awk '{print "ABC="$0}'

1 Answer 1

1

Give this a try:

ffprobe cmd... 2>&1|awk '{print "ABC="$1}' >output.txt
Sign up to request clarification or add additional context in comments.

2 Comments

"2>&1 | awk '{print "ABC="$0}'" fixed it. Had to use $0
@temuri I took the $1 just from your original codes, I have no idea which part do you really need (whole line vs the 1st field). However, it is irrelevant. The point here is, which stderr you should redirect.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.