I have a Python script that I want to create a child process with stdout and stderr redirected to a file. My current approach is as follows:
import subprocess
p = subprocess.Popen("/path/to/something",
stdout=open("/var/log/something.log", "a+"),
stderr=subprocess.STDOUT)
This is similar to what I want, but nothing is written to the log file from stdout until the child process is interrupted. Without changing the child process, is it possible to release the output stream in the same way as if stdout were displayed in the console? Stderr seems to work fine.
I tried using bufsize=1as in the docs say: "1 means line buffering."
source
share