Through the subprocess run the command. The task is to output the executable command to the log and get the exit code of the executable command. Print to the log, I understand how, but how to get another return code and depending on this, it is not clear what to do.
Code example:
rsync = 'rsync /tmp/1 /tmp/2' command_process = subprocess.Popen( rsync, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, ) command_output = command_process.communicate()[0] debbug_rsync = open('debbug_rsync.log', 'a+') debbug_rsync.write('[ {} ]'.format(datetime.now().strftime('%Y-%m-%d %H:%M:%S'))) debbug_rsync.write(rsync + '\n') debbug_rsync.write(command_output) debbug_rsync.close()