Using Python, I want to create a subprocess and have its output redirected to both a file AND the console.
I found this post explaining how to print to both console and file, but solutions does not work when creating a subprocess:
sys.stdout = Logger()
print( "Hello") # printed to console and file
res = subprocess.call(cmd) # command output is printed to console only
Same behaviour here:
with Tee('outfile.log', 'w'):
print( "Hello" )
res = subprocess.call(cmd)
How can I redirect subprocess output both to console (for user) and to file (for me to check it from my code).
Note: Im' on Windows, so using system's tee
is not appropriate.