From 00cf68fa3ea894b8410de14411a4a5e3ac5e47ea Mon Sep 17 00:00:00 2001 From: Einar Forselv Date: Wed, 4 Dec 2019 01:57:52 +0100 Subject: [PATCH] Properly capture stdout an std err in backup_from_stdin --- restic_compose_backup/restic.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/restic_compose_backup/restic.py b/restic_compose_backup/restic.py index 95f2ef5..218ccd2 100644 --- a/restic_compose_backup/restic.py +++ b/restic_compose_backup/restic.py @@ -41,8 +41,16 @@ def backup_from_stdin(repository: str, filename: str, source_command: List[str]) # pipe source command into dest command source_process = Popen(source_command, stdout=PIPE) - dest_process = Popen(dest_command, stdin=source_process.stdout) - dest_process.communicate() + dest_process = Popen(dest_command, stdin=source_process.stdout, stdout=PIPE, stderr=PIPE) + stdout, stderr = dest_process.communicate() + + if stdout: + for line in stdout.decode().split('\n'): + logger.debug(line) + + if stderr: + for line in stderr.decode().split('\n'): + logger.error(line) # Ensure both processes exited with code 0 source_exit, dest_exit = source_process.poll(), dest_process.poll()