How to use a custom file-like object as subprocess stdout/stderr?
According to the documentation:
stdin, stdout and stderr specify the executed program’s standard input, standard output and standard error file handles, respectively. Valid values are PIPE, DEVNULL, an existing file descriptor (a positive integer), an existing file object, and None.
Using subprocess.PIPE
:
proc = subprocess.Popen(['bash', '-c', 'echo Testing'],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
print('Writing:', proc.stdout.read())
# OR print('Writing:', proc.stdout.read().decode())