I am trying to get the realtime output as well as the full output. I have the below code that outputs the realtime output of the command very well but I also need to capture the full output which can then be sent in an email without interrupting the realtime output
backup = subprocess.Popen("rsync ....", shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(backup.stdout.readline, b''):
print(">>> " + line.rstrip())
I have tried adding the following but it causes the realtime output not to display
output = backup.stdout.read()