Preliminary note
I haven't tested davinci-resolve
at all. This answer is designed to be generic.
Analysis
Your shell waits for davinci-resolve
to exit before it puts itself back in the foreground and prints the prompt. Apparently some child (or further descendant) of the main davinci-resolve
prints the unwanted message after the main process exits and the shell reacts.
Solution
A solution may be as easy as:
davinci-resolve | cat
The trick is cat
won't exit until all processes writing to the pipe close their end of the pipe. The troublesome child probably inherits the stdout from the main davinci-resolve
, so cat
will wait for it. Normally this will work even if the unwanted message is printed to stderr or /dev/tty
(i.e. it bypasses our cat
). What matters is the child keeps the pipe open, even if it's printing to elsewhere.
There are disadvantages:
The exit status of the entire pipe will come from cat
, not from davinci-resolve
. In some shells you can do something about it.
stdout and stderr from davinci-resolve
(and its descendants) will lose sync because the former goes via cat
and the latter doesn't.
If you Ctrl+c then you will kill the cat
, possibly before the other processes finish printing, so you may miss some output you do want to see. Additionally if the troublesome message gets printed to stderr then it will be printed anyway, possibly after you see the prompt.
You can make the cat
immune to Ctrl+c though:
davinci-resolve | sh -c 'trap "" INT; exec cat'
The troublesome process may close or redirect its stdout early and still print to stderr. In this case cat
will not wait for it.
The troublesome process may be designed to remain and the unwanted message does not mean the process exits. If the process remains and keeps the pipe open then our cat
will remain; you obviously don't want this. It seems unlikely any descendant of davinci-resolve
remains (unless there's a bug), but in general it may happen.
For some of these reasons you may want to pass stdout and stderr via cat
. Making the cat
immune to Ctrl+c is still a good idea:
davinci-resolve 2>&1 | sh -c 'trap "" INT; exec cat'
Note now you cannot tell apart stderr of davinci-resolve
(and its descendants) from stdout, they both go via cat
and its stdout. It shouldn't be a problem, as you wanted them to mix in the terminal anyway. If you ever want to redirect or capture them separately then you should drop our contraption and start from scratch.
It may be the troublesome process closes or redirects its stdout and stderr early, and it prints the unwanted message directly to /dev/tty
(example). In this case our cat
cannot help.
Shell function
You can implement our solution as a shell function:
davinci-resolve() {
command davinci-resolve "$@" 2>&1 | sh -c 'trap "" INT; exec cat'
}
The function supports passing arguments to davinci-resolve
, but its exit status comes from cat
, not from davinci-resolve
process (if it's a problem then see the already given link for ideas).
nohup davinci-resolve
? – Chris Davies Apr 05 '22 at 19:13