Search code examples
c++linuxcommand-line-interfaceipc

How to get live, non-blocking output from process


I want to be able to capture the output of a cli program (before it terminates) for which I don't have the source code.

Everything I have found was either done with pipes, which to my understanding only send the output on a flush or on exit of the program. One solution I have found on Codeproject is only for Windows.


Solution

  • You can use stdbuf to force stdout and stderr of an application to be line-buffered, even when redirected into a pipe or a file:

    stdbuf --output=L --error=L <program> | ...