Python Forum
run a command, capture output, what form do you want?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
run a command, capture output, what form do you want?
#6
(Oct-28-2022, 11:27 PM)Skaperen Wrote: the question is, what way would you like to have your code get this data?
The way you describe the problem, it it clear that the subprocess' stdout becomes a source of data that must be read as soon as it is available, so the following should work
  1. Create an instance of selectors.DefaultSelector and register EVENT_READ for the subprocess' stdout in this instance.
  2. Call the select() method, which returns a real time sequence of when data has been produced by the subprocess. For each event in the sequence, invoke a callback that reads in the subprocess stdout and attach a time information to the data by calling for example time.perf_counter().
  3. If the program needs to do something else at the same time, create a thread devoted to reading the subprocess' output. Clearly the thread that receives the data must not do anything else, otherwise the time information will be damaged.
Reply


Messages In This Thread
RE: run a command, capture output, what form do you want? - by Gribouillis - Oct-29-2022, 08:08 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  how to capture output from license() in one Python process? Skaperen 0 1,559 Dec-08-2022, 03:35 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