I am trying to run a shell command via subprocess.run
, and I would like to redirect the output to a file, but also display it on stdout at the same time.
I have not found a way to do it, is this possible in a pure Python script?
It would be equivalent to doing some_command | tee file.txt
in bash.
I could always write a wrapper bash script that will invoke the python script and call tee, but would be nice if Python had a way to do this directly.