I am writing a utility to run programs, and I need to grab the unbuffered stdout and stderr from programs. I need:
- Capture stdout and stderr to split files.
- The output should not be buffered (or buffered by line).
- Without changing the source of the program being launched.
The problem is that when the pipeline is sent to the file, the stdout stream becomes block rather than buffered. If the program crashes, the output never lights up and is empty. Therefore, I need to write stdout without buffering (or using string buffering).
I think this can be done with pty, but it's hard for me to find any examples that do exactly what I want (most ignore stderr). In fact, I'm not sure I found all the pty examples in C in general; most use a higher level interface such as Python pty and subprocess modules.
Can anyone help (with code snippets or links)? Any help would be appreciated.
EDIT: I think I decided. The following two links were very helpful.
My code is available as a repository:
source
share