Consider this code, where a subprocess.Popen is spawned. I'd like writes to the subprocess' stdout and stderr to go to my custom file-object's .write() method, however this isn't the case.
import subprocess
class Printer:
def __init__(self):
pass
def write(self, chunk):
print('Writing:', chunk)
def fileno(self):
return 0
def close(self):
return
proc = subprocess.Popen(['bash', '-c', 'echo Testing'],
stdout=Printer(),
stderr=subprocess.STDOUT)
proc.wait()
Why is the .write() method not used, and what is the use of specifying a stdout= parameter in this case?