On 5/10/23 12:51, Dieter Maurer wrote:
Horst Koiner wrote at 2023-5-9 11:13 -0700:
...
For production i run the program with stdout=subprocess.PIPE and i can fetch
than the output later. For just testing if the program works, i run with
stdout=subprocess.STDOUT and I see all program output on the console, but my
program afterwards crashes since there is nothing captured in the python
variable. So I think I need to have the functionality of subprocess.PIPE and
subprcess.STDOUT sametime.
You might want to implement the functionality of the *nix programm
`tee` in Python.
`tee` reads from one file and writes the data to several files,
i.e. it multiplexes one input file to several output files.
Pyhton's `tee` would likely be implemented by a separate thread.
For your case, the input file could be the subprocess's pipe
and the output files `sys.stdout` and a pipe created by your own
used by your application in place of the subprocess's pipe.
should you choose to go this route, there are multiple efforts floating
around on the internet, worth a look. Don't know which are good and
which aren't. Went looking once to see if there was something to
replace a homegrown function that wasn't reliable - ended up solving
that particular problem a different way so didn't use any of the tees.
--
https://mail.python.org/mailman/listinfo/python-list