Python Forum

Full Version: reading from 2 pipes
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i want to write a script that runs a command and reads both its stdout and its stderr (via separate pipes) to prefix each line with a timestamp. then what was read from that command's stdout is written to the scipt's stdout and what was read from that command's stderr is written to the script's stderr. i see 2 major ideas how to do this. one is to start 3 processes, one to run the command, and 2 separate processes to read from each pipe to prefix every line. a variation of this first idea would be to use threads for reading the pipes. the second idea is to multiplex the 2 pipes by using poll to wake up when either of the pipes had data to read.read from the appropriate pipe, add the timestap,andwrite it to the appropriate output. a third way is ... i don't have a third way. i am hoping there is a module that could make a third way be possible. it would have a function to read from both pipes and return whatever is read, and identifying which pipe it read it from. does anyone know of a module like this? or should i write such a module?
Why not logging...
(Oct-05-2018, 12:59 AM)wavic Wrote: [ -> ]Why not logging...
i don't get your thought on this.