I am trying to make a simple script to automate and log synchronization via Unison. I am also using subprocess.Popen rather than the usual os.system call as it's deprecated. I've spent the past 2 days looking at docs and such trying to figure out what I'm doing wrong, but for some reason if I call unison from a terminal it works no problem, yet when I make the same call from Python it tries to do user interaction and in addition I'm not capturing but about half of the output, the other is still printing to the terminal.
Here is my code I am trying to use:
sync = Popen(["unison", "sync"], shell = True, stdout = PIPE)
for line in sync.stdout
logFile.write(line)
sync.wait()
if sync.returncode == 0 or sync.returncode == None:
logFile.write("Sync Completed Successfully\n")
else
logFile.write("!! Sync Failed with a returncode of: " + str(sync.returncode) + "\n")
Here is my Unison config file:
root = /home/zephyrxero/temp/
root = /home/zephyrxero/test/
auto = true
batch = true
prefer = newer
times = true
owner = true
group = true
retry = 2
What am I doing wrong? Why isn't all output from Unison getting saved to my logfile, and why is it asking me for confirmation when the script runs, but not when I run it plainly from a terminal?
UPDATE: Ok, thanks to Emil I'm now capturing all the output, but I still can't figure out why typing "unison sync" into a terminal is getting different results than when calling it from my script.