From 956d916002708e05ef14a8ce3dcc7b1f4a202050 Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Thu, 11 Aug 2022 17:37:29 -0300 Subject: [PATCH] Another idea --- tee.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tee.py b/tee.py index 9b0284f..5cbe745 100644 --- a/tee.py +++ b/tee.py @@ -31,6 +31,13 @@ def main(): with Tee('tee.txt', 'w') as target: subprocess.run('ls', stdout=target, check=False) + with open('tee2.txt', 'w') as output: + with subprocess.Popen('ls', stdout=subprocess.PIPE, stderr=subprocess.PIPE) as proc: + for line in proc.stdout: + print(f'--> {line.decode("utf-8")}', file=output) + result = subprocess.CompletedProcess(proc.args, proc.returncode, proc.stdout, proc.stderr) + print(result) + if __name__ == '__main__': main()