Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
reading from 2 pipes
#1
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?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Why not logging...
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Oct-05-2018, 12:59 AM)wavic Wrote: Why not logging...
i don't get your thought on this.
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  how to run linux command with multi pipes by python !! evilcode1 2 6,219 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  Duplex pipes GrahamL 0 1,726 Dec-16-2020, 09:44 AM
Last Post: GrahamL
  waiting for the first of many pipes to send data Skaperen 7 3,912 May-05-2019, 10:57 PM
Last Post: Skaperen
  reading from two or more pipes Skaperen 2 3,845 Dec-28-2016, 03:06 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020