I've been having some problems with vimdiff, python and daemons.
The thing is, I cannot use vimdiff with python when running the program as a daemon, I don't know what happens it just doesn't generate the diff.html file. It's not a permission issue. My solution for this problem was to add a & to the end of the command, but the diff.html has not the usual vimdiff highlight, and I really want it to output with the highlight.
Does anyone knows how to run the vimdiff from python without loosing it's properties?
I'm using the daemon.DaemonContext()
function from the python-daemon library to run the program as a daemon.
Snippet:
from os import system
def generate_diff(old_file, new_file):
system("vimdiff "+ old_file +" "+ new_file +" -c TOhtml -c 'w! diff.html' -c 'qa!' &")
When you run things are a daemon process the environments are not set the same way as when you run in a terminal.
Your home .profile is not executed for examples. The home directory will not be set the same way, so tools like vim or vimdiff will not read in their .vimrc so all those personalized configurations will not be there.
So odds are the PATH is not setup to the point where it will find the command (aka /usr/bin is not in there).
Easy to test, create a script that will print out the env to a log file or something at call it instead.
So use the full path for the command you are trying to use. Or create a script that will setup the environment with everything your command needs and call it instead.
PS: May I also suggest using Python subprocess module instead of building a command line like you are doing, especially since you are running it in the background. https://docs.python.org/3/library/subprocess.html
Security consideration: I very much hope the old_file and new_file are not arguments controlled by a user. The daemon process is most likely running as root, and if you run your command as is, any command could be passed in as "file names" and run on your system as a privileged user. This is very dangerous. at least put single quotes around it so that the string is not interpreted. and validate that the values are valid existing files before calling your command.