I have a binary named A that generates output when called. If I call it from a Bash shell, most of the output is suppressed by A > /dev/null. All of the output is suppressed by A &> /dev/null
I have a python script named B that needs to call A. I want to be able to generate output from B, while suppressing all the output from A.
From within B, I've tried os.system('A'), os.system('A > /dev/null'), and os.system('A &> /dev/null'), os.execvp('...'), etc. but none of those suppress all the output from A.
I could run B &> /dev/null, but that suppresses all of B's output too and I don't want that.
Anyone have suggestions?
If your search engine lead you to this old question (like me), be aware that using PIPE may lead to deadlocks.
Indeed, because pipes are buffered, you can write a certain number of bytes in a pipe, even if no one read it. However the size of buffer is finite. And consequently if your program A has an output larger than the buffer, A will be blocked on writing, while the calling program B awaits the termination of A. But not, in this particular case... see comments below.
Still, I recommend using Devin Jeanpierre and DNS' solution.
Suppress output in Python calls to executables