0

I am using Popen to start a background process and I am writing the stdout and stderr to a file:

with open("log.log", "w+", buffering=1) as out:
    p = subprocess.Popen(["run", "cmd"], stdout=out, stderr=out, bufsize=1)

Is it possible to also display stdout and stderr in shell (i.e., on screen)?

I am aware that I could use a PIPE for it, but then my code would block for execution of Popen.

martineau
  • 119,623
  • 25
  • 170
  • 301
fsociety
  • 1,791
  • 4
  • 22
  • 32
  • Have you seen this question and answers to it? https://stackoverflow.com/q/803265/4440387 – Denis Rasulev Jun 14 '21 at 13:07
  • This and similar solutions are using PIPE, but then I would need to iterate over it in my code, which would block other execution. – fsociety Jun 14 '21 at 13:37
  • you can shuffle display off to a thread, which you may want to do anyways to serialize output from multiple sources (via a [queue](https://stackoverflow.com/a/57809668/4541045)?) – ti7 Jun 14 '21 at 13:40

0 Answers0