From f8a9f0e7e9e43c423d909b89e9565a028e993b51 Mon Sep 17 00:00:00 2001
From: Einar Forselv <eforselv@gmail.com>
Date: Wed, 4 Dec 2019 03:12:13 +0100
Subject: [PATCH] Support running commands capturing stdout

---
 restic_compose_backup/commands.py | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/restic_compose_backup/commands.py b/restic_compose_backup/commands.py
index aa2d559..539afca 100644
--- a/restic_compose_backup/commands.py
+++ b/restic_compose_backup/commands.py
@@ -1,5 +1,5 @@
 import logging
-from typing import List
+from typing import List, Tuple
 from subprocess import Popen, PIPE
 
 logger = logging.getLogger(__name__)
@@ -66,3 +66,10 @@ def run(cmd: List[str]) -> int:
 
     logger.debug("returncode %s", child.returncode)
     return child.returncode
+
+
+def run_capture_std(cmd: List[str]) -> Tuple[str, str]:
+    """Run a command with parameters and return stdout, stderr"""
+    logger.debug('cmd: %s', ' '.join(cmd))
+    child = Popen(cmd, stdout=PIPE, stderr=PIPE)
+    return child.communicate()