Python Forum
Get stdout of a running process
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get stdout of a running process
#1
Hi,

I'm working on a program that launch multiple subprocess in background.
Those processes return data continuously so I piped stdout to a file, to retrieve it later while running, with a command like myApp --show processName

subprocess.Popen(cmd, stdout=logfile, stderr=logfile, text=True)
It works fine, I loop over the file by reading lines but it's slow and I lose the colored formated text (warnings and errors) threw by the command. It's faster when reading /proc/pid/fd/1 but still slow.

So I'm wondering if there's any way to get the stdout of a running process with it's pid?

Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Problem running external process rjdegraff42 0 339 Mar-19-2025, 07:50 PM
Last Post: rjdegraff42
  subprocess_run and stdout flux paul18fr 2 556 Jan-09-2025, 08:50 PM
Last Post: Gribouillis
  Failing to iterate over captured StdOut tester_V 4 1,579 Jul-12-2024, 03:36 PM
Last Post: deanhystad
  [subprocess] Why stdout sent to stderr? Winfried 3 2,154 Jan-26-2024, 07:26 PM
Last Post: snippsat
  Performance options for sys.stdout.writelines dgrunwal 11 6,218 Aug-23-2022, 10:32 PM
Last Post: Pedroski55
  Controlling what get outputted to stdout when running external commands Daring_T 4 3,689 Jan-30-2022, 05:40 PM
Last Post: bowlofred
  changing stdout and stderr Skaperen 4 4,109 Dec-02-2020, 08:58 PM
Last Post: Skaperen
  will with sys.stdout as f: close sys.stdout? Skaperen 9 7,121 Nov-03-2019, 07:57 AM
Last Post: Gribouillis
  How to sharing object between multiple process from main process using Pipe Subrata 1 4,481 Sep-03-2019, 09:49 PM
Last Post: woooee
  Add stdout to text file maxtimbo 3 4,037 Feb-05-2019, 12:53 AM
Last Post: maxtimbo

Forum Jump:

User Panel Messages

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