I have a running server with Django. After receiving a request I want to start a python script with parameters running in the background and not blocking the server. Also I want to write all the logs to a log file. A working command to start the script is:
python -u script.py --param1=value1 --param2=value2 > log.txt
But when I try to run the script from my server script with the same functionality it does not work. I tried os.system(), execfile() and various forms of subprocess.Popen() but nothing worked.
Examples:
Popen("python -u " + scriptPath + paramString + " > " + LOG_DIR + "\\log.txt", creationflags=CREATE_NEW_CONSOLE)
os.system("python -u " + scriptPath + paramString + " > " + LOG_DIR + "\\log.txt")
Sometimes the script is executed but the logging does not work and sometimes nothing works. Is there a solution to my problem?