I need to execute a script in the background through a service.
The service kicks off the script using Popen.
p = Popen('/path/to/script/script.py', shell=True)
Why doesn't the following script work when I include the file writes in the for loop?
#!/usr/bin/python
import os
import time
def run():
fd = open('/home/dilleyjrr/testOutput.txt', 'w')
fd.write('Start:\n')
fd.flush()
for x in (1,2,3,4,5):
fd.write(x + '\n')
fd.flush()
time.sleep(1)
fd.write('Done!!!!\n')
fd.flush()
fd.close()
if __name__ == '__main__':
run()