From 7756236e1c6327ea2b836fd1201de125aed8d28e Mon Sep 17 00:00:00 2001 From: Peter Leurs Date: Sun, 29 Dec 2024 16:49:00 +0100 Subject: [PATCH] flush output This will ensure that the stderr and stdout are running synchroniously. The output in journalctl will now make more sense. --- backupmanager.j2 | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backupmanager.j2 b/backupmanager.j2 index dcc41ed..b5f6fdf 100644 --- a/backupmanager.j2 +++ b/backupmanager.j2 @@ -47,7 +47,11 @@ def run_command(command, env=None): current_env = os.environ.copy() if env is not None: current_env.update(env) + sys.stdout.flush() + sys.stderr.flush() process = subprocess.run(command, shell=True, env=current_env) + sys.stdout.flush() + sys.stderr.flush() if process.returncode != 0: raise RuntimeError(f"Command '{command}' failed with return code {process.returncode}, environment is {env}") @@ -55,8 +59,12 @@ def get_command(command, env=None, full_return=False): current_env = os.environ.copy() if env is not None: current_env.update(env) + sys.stdout.flush() + sys.stderr.flush() process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, env=current_env) output, error = process.communicate() + sys.stdout.flush() + sys.stderr.flush() return_code = process.poll() if full_return: return output.decode().strip(), error.decode().strip(), return_code